A14062 | Last Year's Substring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp has a string $s[1 \dots n]$ of length $n$ consisting of decimal digits. Polycarp performs the following operation with the string $s$ no more than once (i.e. he can perform operation $0$ or $1$ time):
- Polycarp selects two numbers $i$ and $j$ ( $1 \leq i \leq j \leq n$ ) and removes characters from the $s$ string at the positions $i, i+1, i+2, \ldots, j$ (i.e. removes substring $s[i \dots j]$ ). More formally, Polycarp turns the string $s$ into the string $s_1 s_2 \ldots s_{i-1} s_{j+1} s_{j+2} \ldots s_{n}$ .
For example, the string $s = $ "20192020" Polycarp can turn into strings:
- "2020" (in this case $(i, j)=(3, 6)$ or $(i, j)=(1, 4)$ );
- "2019220" (in this case $(i, j)=(6, 6)$ );
- "020" (in this case $(i, j)=(1, 5)$ );
- other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string $s$ into a string "2020" in no more than one operation? Note that you can perform zero operations.
- Polycarp selects two numbers $i$ and $j$ ( $1 \leq i \leq j \leq n$ ) and removes characters from the $s$ string at the positions $i, i+1, i+2, \ldots, j$ (i.e. removes substring $s[i \dots j]$ ). More formally, Polycarp turns the string $s$ into the string $s_1 s_2 \ldots s_{i-1} s_{j+1} s_{j+2} \ldots s_{n}$ .
For example, the string $s = $ "20192020" Polycarp can turn into strings:
- "2020" (in this case $(i, j)=(3, 6)$ or $(i, j)=(1, 4)$ );
- "2019220" (in this case $(i, j)=(6, 6)$ );
- "020" (in this case $(i, j)=(1, 5)$ );
- other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string $s$ into a string "2020" in no more than one operation? Note that you can perform zero operations.
输入格式
The first line contains a positive integer $t$ ( $1 \leq t \leq 1000 $ ) — number of test cases in the test. Then $t$ test cases follow.
The first line of each test case contains an integer $n$ ( $4 \leq n \leq 200$ ) — length of the string $s$ . The next line contains a string $s$ of length $n$ consisting of decimal digits. It is allowed that the string $s$ starts with digit 0.
The first line of each test case contains an integer $n$ ( $4 \leq n \leq 200$ ) — length of the string $s$ . The next line contains a string $s$ of length $n$ consisting of decimal digits. It is allowed that the string $s$ starts with digit 0.
输出格式
For each test case, output on a separate line:
- "YES" if Polycarp can turn the string $s$ into a string "2020" in no more than one operation (i.e. he can perform $0$ or $1$ operation);
- "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
- "YES" if Polycarp can turn the string $s$ into a string "2020" in no more than one operation (i.e. he can perform $0$ or $1$ operation);
- "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
输入输出样例
输入 #1
6 8 20192020 8 22019020 4 2020 5 20002 6 729040 6 200200
输出 #1
YES YES YES NO NO NO
In the first test case, Polycarp could choose $i=3$ and $j=6$ .
In the second test case, Polycarp could choose $i=2$ and $j=5$ .
In the third test case, Polycarp did not perform any operations with the string.
In the second test case, Polycarp could choose $i=2$ and $j=5$ .
In the third test case, Polycarp did not perform any operations with the string.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted