No.2692 How Many Times Reached?
Problem Statement
$A$ and $B$ are playing a territory game on an $N \times N$ board. The cell in the $i$-th row from the top and the $j$-th column from the left is called cell $(i,j)$ .
Initially, every cell has . written on it.
$A$ and $B$ repeat the following operations.
- $A$ chooses exactly $1$ cell with
.written on it and repaints it toA. - If the board has a bingo of $A$, then $A$ wins. Otherwise, $B$ chooses exactly $1$ cell with
.written on it and repaints it toB. - If the board has a bingo of $B$, then $B$ wins. Otherwise, return to 1.
A bingo is a state in which, for the most recently repainted cell, the same character as that cell continues for $N$ cells along a single vertical, horizontal, or diagonal straight line.
$A$ noticed on a certain turn that there exists a reach of their own.
A reach is a vertical, horizontal, or diagonal straight line that can be turned into a bingo by repainting an appropriate . cell.
Currently, each cell has one of the characters A , B , . written on it.
The characters written on the cells are represented by $N$ strings $S_{1},S_{2},\dots,S_{N}$ of length $N$, and the character written on cell $(i,j)$ is equal to the $j$-th character of the string $S_{i}$.
Find the number of reaches of $A$ on the given board.
Input
$N$
$S_{1}$
$S_{2}$
$\vdots$
$S_{N}$
- $2 \leq N \leq 100$
- $S_{i}$ is a string of length $N$ consisting only of
A,B, and. - It is guaranteed that the given board has at least $1$ reach and is not in a bingo state.
Output
Find the number of lines on which $A$ has a reach on the given board.
Sample
Sample 1
Input
3 A.B AB. ...
Output
1
$A$ can fill column $1$ with A by repainting cell $(3,1)$.
Sample 2
Input
3 AA. ABB .B.
Output
2
$A$ can fill column $1$ with A by repainting cell $(3,1)$.
Also, repainting cell $(1,3)$ fills row $1$ with A.
Sample 3
Input
3 BAB A.A BAB
Output
2
$A$ can fill both row $2$ and column $2$ with A by repainting cell $(2,2)$.
In this way, the total number of reaches can be $2$ or more even if only $1$ cell is repainted.
Sample 4
Input
6 AAAAA. BBBBB. AAAAA. BBBBB. AAAAA. BBBBB.
Output
3
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
hibit_at
MM