#abc377b. B - Avoid Rook Attack
B - Avoid Rook Attack
Score : points
问题陈述
有一个由 个方格组成的棋盘,分为 行和 列。用 表示从顶部数第 行 和从左边数第 列 的方格。
每个方格要么为空,要么上面放置了一个棋子。方格的状态由一个长度为 的字符串序列 表示。如果 中的第 个字符是 .
,则方格 为空;如果是 #
,则表示有棋子。
你想要在一个 空方格 上放置你的棋子,使得它 不能被任何现有的棋子捕获。
放置在方格 上的棋子可以捕获满足以下任一条件的棋子:
- 放置在第 行的方格上
- 放置在第 列的方格上
例如,放置在方格 上的棋子可以捕获下图中蓝色显示的方格上的棋子:
你可以在多少个方格上放置你的棋子?
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a grid of squares with rows and columns. Let denote the square at the -th row from the top and -th column from the left .
Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence of strings of length . Square is empty if the -th character of is .
, and has a piece if it is #
.
You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.
A piece placed on square can capture pieces that satisfy either of the following conditions:
- Placed on a square in row
- Placed on a square in column
For example, a piece placed on square can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on?
Constraints
- Each is a string of length consisting of
.
and#
.
Input
The input is given from Standard Input in the following format:
Output
Print the number of empty squares where you can place your piece without it being captured by any existing pieces.
Sample Input 1
...#....
#.......
.......#
....#...
.#......
........
........
..#.....
Sample Output 1
4
The existing pieces can capture pieces placed on the squares shown in blue in the following figure:
Therefore, you can place your piece without it being captured on squares: square , square , square , and square .
Sample Input 2
........
........
........
........
........
........
........
........
Sample Output 2
64
There may be no pieces on the grid.
Sample Input 3
.#......
..#..#..
....#...
........
..#....#
........
...#....
....#...
Sample Output 3
4