CF2200C.Specialty String
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
AksLolCoding is playing a game on a string s of length n. Initially, s contains only lowercase Latin characters.
In one turn, AksLolCoding can choose any pair of integers (i,j) such that:
- 1≤i<j≤n;
- si=sj=∗; and
- sk=∗ for all i<k<j.
If no such i,j exists, then the game ends. Otherwise, AksLolCoding sets si:=∗ and sj:=∗.
Once the game ends, AksLolCoding wins if and only if every character in s is equal to ∗. Determine if it is possible for AksLolCoding to win.
Note: ∗ represents ASCII character 42.
AksLolCoding 正在对一个长度为 n 的字符串 s 进行一场游戏。初始时,s 仅包含小写拉丁字母。
在每一轮中,AksLolCoding 可以任选一对整数 (i,j),满足以下条件:
- 1≤i<j≤n;
- si=sj=∗;且
- 对所有满足 i<k<j 的 k,均有 sk=∗。
若不存在满足上述条件的 (i,j),则游戏结束。否则,AksLolCoding 将 si 和 sj 均设为 ∗。
当游戏结束时,当且仅当字符串 s 中每个字符均为 ∗ 时,AksLolCoding 获胜。请判断 AksLolCoding 是否有可能获胜。
注:∗ 表示 ASCII 码为 42 的字符。
输入格式
The first line contains an integer t (1≤t≤100), the number of test cases.
The first line of each test case contains an integer n (1≤n≤5000), the length of the string.
The second line of each test case contains a string s consisting of lowercase Latin characters.
The sum of n over all test cases does not exceed 5000.
第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤5000),表示字符串的长度。
每个测试用例的第二行包含一个字符串 s,由小写拉丁字母组成。
所有测试用例的 n 值之和不超过 5000。
输出格式
Output the answer to each test case on its own line. If AksLolCoding can win, output "YES" (without quotes). Else, output "NO" (without quotes).
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
每个测试用例的答案单独输出一行。如果 AksLolCoding 能获胜,则输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。
答案大小写不限。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为肯定回答。
输入输出样例
输入#1
6 1 a 6 llmllm 6 uwuuwu 6 byebye 6 oooioi 12 siixxsevvenn
输出#1
NO YES YES NO NO YES
说明/提示
In the first test case, it can be shown that it is impossible for AksLolCoding to win.
In the second test case, AksLolCoding can win by making the following moves: llmllm → llm**m → **m**m → ******
In the third test case, AksLolCoding can win by making the following moves: uwuuwu → uw**wu → u****u → ******
在第一个测试用例中,可以证明 AksLolCoding 不可能获胜。
在第二个测试用例中,AksLolCoding 可以通过以下操作获胜:llmllm → llm**m → **m**m → ******
在第三个测试用例中,AksLolCoding 可以通过以下操作获胜:uwuuwu → uw**wu → u****u → ******
输入解题思路,AI测评打分。不知道怎么写?