#abc232d. D - Weak Takahashi
D - Weak Takahashi
Score : points
问题描述
存在一个 矩形网格,其中包含 行(从上至下编号)和 列(从左至右编号)。令 表示第 行从上数起、第 列从左数起的方格。
每个方格由字符 描述,其中若 .
,表示 是一个空方格;若 #
,则表示 是一堵墙。
高桥将在这个网格中开始行走。当他在 位置时,他可以移动到 或者 。但是,他不能走出网格范围,也不能进入墙壁方格。当他无法再前往任何方格时,他会停止行走。
如果高桥从 开始出发,在他停止行走之前,最多能访问多少个方格?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a -square grid with horizontal rows and vertical columns. Let denote the square at the -th row from the top and -th column from the left.
Each square is described by a character , where .
means is an empty square, and #
means is a wall.
Takahashi is about to start walking in this grid. When he is on , he can go to or . However, he cannot exit the grid or enter a wall square. He will stop when there is no more square to go to.
When starting on , at most how many squares can Takahashi visit before he stops?
Constraints
- and are integers.
-
.
or#
. -
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 4
.#..
..#.
..##
Sample Output 1
4
For example, by going $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2)$, he can visit squares.
He cannot visit or more squares, so we should print .
Sample Input 2
1 1
.
Sample Output 2
1
Sample Input 3
5 5
.....
.....
.....
.....
.....
Sample Output 3
9
update @ 2024/3/10 10:06:51