Upload code_segments/segment_267.txt with huggingface_hub
Browse files
code_segments/segment_267.txt
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
A beautiful binary matrix is a matrix that has ones on its edges and zeros inside.
|
2 |
+
|
3 |
+
 Examples of four beautiful binary matrices.
|
4 |
+
|
5 |
+
Today, Sakurako was playing with a beautiful binary matrix of size $r \times c$ and created a binary string $s$ by writing down all the rows of the matrix, starting from the first and ending with the $r$-th. More formally, the element from the matrix in the $i$-th row and $j$-th column corresponds to the $((i-1)*c+j)$-th element of the string.
|
6 |
+
|
7 |
+
You need to check whether the beautiful matrix from which the string $s$ was obtained could be squared. In other words, you need to check whether the string $s$ could have been build from a square beautiful binary matrix (i.e., one where $r=c$).
|
8 |
+
|
9 |
+
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
10 |
+
|
11 |
+
The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the length of the string.
|
12 |
+
|
13 |
+
The second line of each test case contains the string $s$ of length $n$. The string is always the result of writing out the strings of a beautiful matrix.
|
14 |
+
|
15 |
+
It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$.
|
16 |
+
|
17 |
+
Print "Yes", if the original matrix could have been square, and "No" otherwise.
|
18 |
+
|
19 |
+
For the second test case, string 1111 can be obtained from the matrix:
|
20 |
+
|
21 |
+
$1$| $1$ ---|--- $1$| $1$ For the third test case, string 111101111 can be obtained from the matrix:
|
22 |
+
|
23 |
+
$1$| $1$| $1$ ---|---|--- $1$| $0$| $1$ $1$| $1$| $1$ There is no square matrix in the fourth case, such that the string can be obtained from it.
|