CF1632A.ABC

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently, the students of School 179 have developed a unique algorithm, which takes in a binary string ss as input. However, they soon found out that if some substring tt of ss is a palindrome of length greater than 1, the algorithm will work incorrectly. Can the students somehow reorder the characters of ss so that the algorithm will work correctly on the string?

A binary string is a string where each character is either 0 or 1.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

A palindrome is a string that reads the same backwards as forwards.

最近,179 号学校的学生们开发了一种独特的算法,该算法以一个二进制字符串 ss 作为输入。然而,他们很快发现:如果 ss 的某个子串 tt 是长度大于 1 的回文串,则该算法将无法正确运行。学生们能否通过重新排列 ss 中的字符,使得该算法在重排后的字符串上能正确运行?

二进制字符串是指每个字符均为 0 或 1 的字符串。

若字符串 aa 可通过对字符串 bb 删除其开头若干个(可能为零个或全部)字符以及结尾若干个(可能为零个或全部)字符而得到,则称 aa 是 bb 的一个子串。

回文串是指正读与反读都相同的字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the length of the string ss.

The second line of each test case contains the string ss of length nn consisting only of the characters 0 and 1.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 字符串 ss 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss,该字符串仅由字符 0 和 1 组成。

输出格式

For each test case, print YES (case-insensitive) if it is possible to reorder the characters of ss so that there are no substrings that are a palindrome of length greater than 1, or NO (case-insensitive) otherwise.

对于每个测试用例,如果可以重新排列字符串 ss 的字符,使得其中不存在长度大于 1 的回文子串,则输出 YES(不区分大小写);否则输出 NO(不区分大小写)。

输入输出样例

  • 输入#1

    4
    1
    1
    2
    10
    2
    01
    4
    1010

    输出#1

    YES
    YES
    YES
    NO

说明/提示

In the first three test cases, the given strings do not contain palindromes of length greater than 1, so the answers are YES.

In the last test case, it is impossible to reorder the characters so that the string does not contain palindromes of length greater than 1, so the answer is NO.

在前三个测试用例中,给定的字符串不包含长度大于 1 的回文子串,因此答案为 YES。

在最后一个测试用例中,无法重新排列字符使得字符串不包含长度大于 1 的回文子串,因此答案为 NO。

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

首页