103771: [Atcoder]ABC377 B - Avoid Rook Attack

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:24 Solved:0

Description

Score : $200$ points

Problem Statement

There is a grid of $64$ squares with $8$ rows and $8$ columns. Let $(i,j)$ denote the square at the $i$-th row from the top $(1\leq i\leq8)$ and $j$-th column from the left $(1\leq j\leq8)$.

Each square is either empty or has a piece placed on it. The state of the squares is represented by a sequence $(S_1,S_2,S_3,\ldots,S_8)$ of $8$ strings of length $8$. Square $(i,j)$ $(1\leq i\leq8,1\leq j\leq8)$ is empty if the $j$-th character of $S_i$ 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 $(i,j)$ can capture pieces that satisfy either of the following conditions:

  • Placed on a square in row $i$
  • Placed on a square in column $j$

For example, a piece placed on square $(4,4)$ 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 $S_i$ is a string of length $8$ consisting of . and # $(1\leq i\leq 8)$.

Input

The input is given from Standard Input in the following format:

$S_1$
$S_2$
$S_3$
$S_4$
$S_5$
$S_6$
$S_7$
$S_8$

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 $4$ squares: square $(6,6)$, square $(6,7)$, square $(7,6)$, and square $(7,7)$.


Sample Input 2

........
........
........
........
........
........
........
........

Sample Output 2

64

There may be no pieces on the grid.


Sample Input 3

.#......
..#..#..
....#...
........
..#....#
........
...#....
....#...

Sample Output 3

4

Output

得分:200分

问题陈述

有一个由64个方块组成的网格,有8行和8列。 用$(i,j)$表示从顶部第$i$行$(1\leq i\leq8)$和从左边第$j$列$(1\leq j\leq8)$的方块。

每个方块要么是空的,要么上面放了一个棋子。 方块的状态由一个由8个长度为8的字符串组成的序列$(S_1,S_2,S_3,\ldots,S_8)$表示。 如果$S_i$的第$j$个字符是.,那么方块$(i,j)$$(1\leq i\leq8,1\leq j\leq8)$是空的;如果是#,则上面有一个棋子。

你想要在一个空方块上放置你的棋子,以使得它不能被任何现有的棋子捕获

放在方块$(i,j)$上的棋子可以捕获满足以下任一条件的棋子:

  • 放在第$i$行的方块上
  • 放在第$j$列的方块上

例如,放在方块$(4,4)$上的棋子可以捕获如下图中蓝色方块上的棋子:

你可以放置多少个方块让你的棋子不被捕获?

约束条件

  • 每个$S_i$是一个由.#组成的长度为8的字符串$(1\leq i\leq 8)$。

输入

输入从标准输入以下格式给出:

$S_1$
$S_2$
$S_3$
$S_4$
$S_5$
$S_6$
$S_7$
$S_8$

输出

打印出你可以放置棋子而不被任何现有棋子捕获的空方块的数量。


示例输入1

...#....
#.......
.......#
....#...
.#......
........
........
..#.....

示例输出1

4

现有的棋子可以捕获放在如下图中蓝色方块上的棋子:

因此,你可以放置你的棋子而不被捕获在4个方块上:方块$(6,6)$,方块$(6,7)$,方块$(7,6)$,和方块$(7,7)$。


示例输入2

........
........
........
........
........
........
........
........

示例输出2

64

网格上可能没有棋子。


示例输入3

.#......
..#..#..
....#...
........
..#....#
........
...#....
....#...

示例输出3

4

加入题单

上一题 下一题 算法标签: