AtCoder Grand Contest 069
B
Pair Guessing
AtCoder
⌀ 2859
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given $N$ strings $S_1, \ldots, S_N$, each of length $N$, consisting only of 0 and 1. Let $S_{i,j}$ denote the $j$-th character of $S_i$. It is guaranteed by the constraints that there exists at least one integer pair $(i, j)$ satisfying $S_{i,j} =$ 1.

翻译中…

Takahashi and Aoki play the following game:

翻译中…
  1. Takahashi chooses one integer pair $(i, j)$ satisfying $1 \leq i, j \leq N$ and $S_{i,j} =$ 1.
  2. Aoki asks Takahashi at least $0$ and at most $N$ questions. In each question, Aoki chooses an integer pair $(i', j')$ satisfying $1 \leq i', j' \leq N$, and Takahashi tells Aoki whether "At least one of $i = i'$ or $j = j'$ holds" is true or false.
  3. Aoki guesses $(i, j)$. If his guess is correct, Aoki wins; otherwise, he loses.
翻译中…

Aoki knows the possible choices of $(i, j)$ that Takahashi can choose, that is, he knows $S_1, \ldots, S_N$ before playing the game. Also, in step 2, Aoki can choose $(i', j')$ based on the answers to previous questions.

翻译中…

Determine whether Aoki can always win the game regardless of Takahashi's choice of $(i, j)$ and randomness, if he uses an appropriate strategy.

翻译中…

There are $T$ test cases in each input.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 2 \times 10^5$
  • $1 \leq N \leq 500$
  • The sum of $N^2$ over all test cases in each input is at most $500^2$.
  • $S_i$ is a string of length $N$ consisting of 0 and 1.
  • There is at least one integer pair $(i, j)$ satisfying $S_{i,j} =$ 1.
翻译中…

Input

翻译中…

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

翻译中…

T
case_1
\vdots
case_T

翻译中…

Each test case is given in the following format:

翻译中…

N
S_1
\vdots
S_N

翻译中…

Output

翻译中…

For each test case, print Yes if Aoki can always win the game, and No otherwise.

翻译中…

样例

Input #1
3
2
01
11
2
11
11
10
0101011110
1100100001
1101100000
0111101010
1000011001
1110101010
1110110100
1110000110
0000001011
1001111100
Output #1
Yes
No
Yes
In the first test case, an example of the game is as follows: 1. Takahashi chooses $(i, j) = (2, 2)$ satisfying $S_{i,j}=\$`1`. 2. Aoki asks two questions. In the first question, he chooses $(i', j') = (1, 1)$. Takahashi tells him that "At least one of $i = 1$ or $j = 1$ holds" is false. In the second question, he chooses $(i', j') = (2, 2)$. Takahashi tells him that "At least one of $i = 2$ or $j = 2$ holds" is true. 3. Aoki guesses $(i, j) = (2, 2)$. Since his guess is correct, Aoki wins. This is just an example of the game, and Aoki's strategy might not be optimal. However, if Aoki uses an appropriate strategy, he can always win the game, so the output for the first test case is `Yes`.
题目信息
题号
agc069_b
时间限制
2 s
内存限制
2048 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。