CF1462B.Last Year's Substring
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp has a string s[1…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≤i≤j≤n) and removes characters from the s string at the positions i,i+1,i+2,…,j (i.e. removes substring s[i…j]). More formally, Polycarp turns the string s into the string s1s2…si−1sj+1sj+2…sn.
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 有一个长度为 n 的字符串 s[1…n],该字符串仅由十进制数字组成。Polycarp 对字符串 s 最多执行一次如下操作(即他可以执行 0 次或 1 次该操作):
- Polycarp 选择两个数 i 和 j(满足 1≤i≤j≤n),并删除字符串 s 中位置为 i,i+1,i+2,…,j 的字符(即删除子串 s[i…j])。更准确地说,Polycarp 将字符串 s 变为字符串 s1s2…si−1sj+1sj+2…sn。
例如,对于字符串 $s = $"20192020",Polycarp 可将其变为以下字符串:
- "2020"(此时 (i,j)=(3,6) 或 (i,j)=(1,4));
- "2019220"(此时 (i,j)=(6,6));
- "020"(此时 (i,j)=(1,5));
- 其他变换也是可能的,上面仅列出其中几种。
Polycarp 非常喜欢字符串 "2020",因此他想知道:是否能通过至多一次上述操作,将字符串 s 变为字符串 "2020"?注意,你也可以选择不执行任何操作。
输入格式
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≤n≤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.
第一行包含一个正整数 t(1≤t≤1000)——测试中测试用例的数量。随后是 t 个测试用例。
每个测试用例的第一行包含一个整数 n(4≤n≤200)——字符串 s 的长度。下一行包含一个长度为 n 的字符串 s,由十进制数字组成。字符串 s 允许以数字 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).
对于每个测试用例,在单独一行输出:
- 如果 Polycarp 可以在至多一次操作内(即执行 0 次或 1 次操作)将字符串 s 变为字符串 "2020",则输出 "YES";
- 否则输出 "NO"。
你可以以任意大小写形式输出 "YES" 和 "NO" 中的每个字母(例如,字符串 yEs、yes、Yes 和 YES 均会被识别为肯定回答)。
输入输出样例
输入#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.
在第一个测试用例中,Polycarp 可以选择 i=3 和 j=6。
在第二个测试用例中,Polycarp 可以选择 i=2 和 j=5。
在第三个测试用例中,Polycarp 未对字符串执行任何操作。
输入解题思路,AI测评打分。不知道怎么写?