CF1789B.Serval and Inversion Magic

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Serval has a string ss that only consists of 0 and 1 of length nn . The ii -th character of ss is denoted as sis_i , where 1in1\leq i\leq n .

Serval can perform the following operation called Inversion Magic on the string ss :

  • Choose an segment [l,r][l, r] ( 1lrn1\leq l\leq r\leq n ). For lirl\leq i\leq r , change sis_i into 1 if sis_i is 0, and change sis_i into 0 if sis_i is 1.

For example, let ss be 010100 and the segment [2,5][2,5] is chosen. The string ss will be 001010 after performing the Inversion Magic.

Serval wants to make ss a palindrome after performing Inversion Magic exactly once. Help him to determine whether it is possible.

A string is a palindrome iff it reads the same backwards as forwards. For example, 010010 is a palindrome but 10111 is not.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1041\leq t\leq 10^4 ). The description of the test cases follows.

The first line of each test case contains a single integer nn ( 2n1052\leq n\leq 10^5 ) — the length of string ss .

The second line of each test case contains a binary string ss of length nn . Only characters 0 and 1 can appear in ss .

It's guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5 .

输出格式

For each test case, print Yes if ss can be a palindrome after performing Inversion Magic exactly once, and print No if not.

You can output Yes and No in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

输入输出样例

  • 输入#1

    3
    4
    1001
    5
    10010
    7
    0111011

    输出#1

    Yes
    Yes
    No

说明/提示

In the first test case, Serval can perform Inversion Magic on the segment [1,4][1,4] . The string ss will be 0110 after the magic.

In the second test case, Serval can perform Inversion Magic on the segment [1,3][1,3] . The string ss will be 01110 after the magic.

In the third test case, Serval can't make ss a palindrome by performing Inversion Magic exactly once.

首页