欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1324A.Yet Another Tetris Problem
Yet Another Tetris Problem
You are given some Tetris field consisting of columns. The initial height of the -th column of the field is blocks. On top of these columns you can place only figures of size (i.e. the height of this figure is blocks and the width of this figure is block). Note that you cannot rotate these figures.
Your task is to say if you can clear the whole field by placing such figures.
More formally, the problem can be described like this:
The following process occurs while at least one is greater than :
- You place one figure (choose some from to and replace with );
- then, while all are greater than zero, replace each with .
And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.
You have to answer independent test cases.
Input
The first line of the input contains one integer () — the number of test cases.
The next lines describe test cases. The first line of the test case contains one integer () — the number of columns in the Tetris field. The second line of the test case contains integers (), where is the initial height of the -th column of the Tetris field.
Output
For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.
Note
The first test case of the example field is shown below:

Gray lines are bounds of the Tetris field. Note that the field has no upper bound.
One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes . Then place the figure in the second column and after the second step of the process, the field becomes .
And the second test case of the example field is shown below:

It can be shown that you cannot do anything to end the process.
In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes . Then place the figure in the first column and after the second step of the process, the field becomes .
In the fourth test case of the example, place the figure in the first column, then the field becomes after the first step of the process, and then the field becomes after the second step of the process.
Samples
4
3
1 1 3
4
1 1 2 1
2
11 11
1
100
YES
NO
YES
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |