CF1807C.Find and Replace
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s consisting of lowercase Latin characters. In an operation, you can take a character and replace all occurrences of this character with 0 or replace all occurrences of this character with 1 .
Is it possible to perform some number of moves so that the resulting string is an alternating binary string † ?
For example, consider the string abacaba . You can perform the following moves:
- Replace a with 0 . Now the string is 0b0c0b0 .
- Replace b with 1 . Now the string is 010c010 .
- Replace c with 1 . Now the string is 0101010 . This is an alternating binary string.
† An alternating binary string is a string of 0 s and 1 s such that no two adjacent bits are equal. For example, 01010101 , 101 , 1 are alternating binary strings, but 0110 , 0a0a0 , 10100 are not.
输入格式
The input consists of multiple test cases. The first line contains an integer t ( 1≤t≤100 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer n ( 1≤n≤2000 ) — the length of the string s .
The second line of each test case contains a string consisting of n lowercase Latin characters — the string s .
输出格式
For each test case, output "YES" (without quotes) if you can make the string into an alternating binary string, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
输入输出样例
输入#1
8 7 abacaba 2 aa 1 y 4 bkpt 6 ninfia 6 banana 10 codeforces 8 testcase
输出#1
YES NO YES YES NO YES NO NO
说明/提示
The first test case is explained in the statement.
In the second test case, the only possible binary strings you can make are 00 and 11 , neither of which are alternating.
In the third test case, you can make 1 , which is an alternating binary string.