欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2008B.Square or Not
Square or Not
A beautiful binary matrix is a matrix that has ones on its edges and zeros inside.
Examples of four beautiful binary matrices.
Today, Sakurako was playing with a beautiful binary matrix of size and created a binary string by writing down all the rows of the matrix, starting from the first and ending with the -th. More formally, the element from the matrix in the -th row and -th column corresponds to the -th element of the string.
You need to check whether the beautiful matrix from which the string was obtained could be squared. In other words, you need to check whether the string could have been build from a square beautiful binary matrix (i.e., one where ).
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the length of the string.
The second line of each test case contains the string of length . The string is always the result of writing out the strings of a beautiful matrix.
It is guaranteed that the sum of across all test cases does not exceed .
Output
Print "Yes", if the original matrix could have been square, and "No" otherwise.
Note
For the second test case, string 1111 can be obtained from the matrix:
For the third test case, string 111101111 can be obtained from the matrix:
There is no square matrix in the fourth case, such that the string can be obtained from it.
Samples
5
2
11
4
1111
9
111101111
9
111111111
12
111110011111
No
Yes
Yes
No
No
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |