CF1520A.Do Not Be Distracted!

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarp has 2626 tasks. Each task is designated by a capital letter of the Latin alphabet.

The teacher asked Polycarp to solve tasks in the following way: if Polycarp began to solve some task, then he must solve it to the end, without being distracted by another task. After switching to another task, Polycarp cannot return to the previous task.

Polycarp can only solve one task during the day. Every day he wrote down what task he solved. Now the teacher wants to know if Polycarp followed his advice.

For example, if Polycarp solved tasks in the following order: "DDBBCCCBBEZ", then the teacher will see that on the third day Polycarp began to solve the task 'B', then on the fifth day he got distracted and began to solve the task 'C', on the eighth day Polycarp returned to the task 'B'. Other examples of when the teacher is suspicious: "BAB", "AABBCCDDEEBZZ" and "AAAAZAAAAA".

If Polycarp solved the tasks as follows: "FFGZZZY", then the teacher cannot have any suspicions. Please note that Polycarp is not obligated to solve all tasks. Other examples of when the teacher doesn't have any suspicious: "BA", "AFFFCC" and "YYYYY".

Help Polycarp find out if his teacher might be suspicious.

Polycarp 有 2626 个任务,每个任务用一个大写的拉丁字母表示。

老师要求 Polycarp 按如下方式完成任务:如果 Polycarp 开始解决某个任务,则他必须将其彻底完成,期间不能被其他任务打断;一旦切换到另一个任务,Polycarp 就不能再回到之前的任务。

Polycarp 每天只能解决一个任务,且每天他会记录下当天所解决的任务。现在老师想判断 Polycarp 是否遵守了上述要求。

例如,若 Polycarp 解决任务的顺序为 "DDBBCCCBBEZ",则老师会发现:第三天 Polycarp 开始解决任务 'B',第五天他分心转而开始解决任务 'C',第八天 Polycarp 又回到了任务 'B'。其他令老师产生怀疑的情况还有:"BAB"、"AABBCCDDEEBZZ" 和 "AAAAZAAAAA"。

若 Polycarp 解决任务的顺序为 "FFGZZZY",则老师不会产生任何怀疑。请注意,Polycarp 并不一定要完成所有任务。其他老师不会产生怀疑的情况还有:"BA"、"AFFFCC" 和 "YYYYY"。

请帮助 Polycarp 判断他的老师是否可能产生怀疑。

输入格式

The first line contains an integer tt (1≤t≤10001 \le t \le 1000). Then tt test cases follow.

The first line of each test case contains one integer nn (1≤n≤501 \le n \le 50) — the number of days during which Polycarp solved tasks.

The second line contains a string of length nn, consisting of uppercase Latin letters, which is the order in which Polycarp solved the tasks.

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)。随后是 tt 组测试数据。

每组测试数据的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)—— 表示 Polycarp 解题所持续的天数。

每组测试数据的第二行包含一个长度为 nn 的字符串,由大写拉丁字母组成,表示 Polycarp 解题的顺序。

输出格式

For each test case output:

  • "YES", if the teacher cannot be suspicious;
  • "NO", otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

对于每个测试用例,输出:

  • 若教师不会产生怀疑,则输出 "YES";
  • 否则输出 "NO"。

你可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被识别为肯定回答)。

输入输出样例

  • 输入#1

    5
    3
    ABA
    11
    DDBBCCCBBEZ
    7
    FFGZZZY
    1
    Z
    2
    AB

    输出#1

    NO
    NO
    YES
    YES
    YES

输入解题思路,AI测评打分。不知道怎么写?

首页