Red and Black


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
Python

Black Tile Counting

There is a rectangular room with square tiles in two colors: red and black.

You are standing on one of the black tiles and can only move to adjacent (up, down, left, or right) black tiles.

Write a program that calculates the total number of black tiles you can reach.

Input Format

The first line contains two integers W and H, representing the number of tiles in the x-direction and y-direction, respectively.

The next H lines each contain W characters. Each character represents the color of a tile, according to the following rules:

1) '.': a black tile
2) '#': a red tile
3) '@': a black tile on which you are standing. This character appears exactly once in each data set.

Output Format
output a single line showing the number of tiles you can reach starting from the initial position (counting includes the initial tile).

Data Range
1 ≤ W, H ≤ 1000

Sample Input:

6 9  
....#.
.....#
......
......
......
......
......
#@...#
.#..#.

Sample Output:

45

Comments


  • 0
    stephengzy___PYTHON  commented on Nov. 3, 2025, 4:01 a.m.
    6 9  
    ....#.
    .....#
    ......
    ......
    ......
    ......
    ......
    #@...#
    .#..#.

    • 0
      stephengzy___PYTHON  commented on Nov. 3, 2025, 4:02 a.m.

      correct sample input and output without random spaces