P14611 [CodeChef] FLIPPAL
普及-
题目描述

Chef has a binary string S of length N.

In one operation, Chef can:
Select two indices i and j (1 ≤ i, j ≤ $N, i \ne j)$ and flip S_{i} and S_{j}. (i.e. change 0 to 1 and 1 to 0)

For example, if S = 10010 and chef applys operation on i = 1 and j = 3 then: $\underline{1}0\underline{0}10 \rightarrow 00110$.

Find if it is possible to convert S to a palindrome by applying the above operation any (possibly zero) number of times.

Note: A string is called a palindrome if it reads the same backwards and forwards, for e.g. 10001 and 0110 are palindromic strings.

------ Input Format ------

  • The first line contains a single integer T — the number of test cases. Then the test cases follow.
  • The first line of each test case contains an integer N — the length of the binary string S.
  • The second line of each test case contains a binary string S of length N containing 0s and 1s only.

------ Output Format ------

For each test case, output YES if it is possible to convert S to a palindrome. Otherwise, output NO.

You can print each character of the string in uppercase or lowercase. For example, the strings YES, yes, Yes, and yEs are all considered the same.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$S$ contains $0$ and $1$ only.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
3
6
101011
2
01
7
1110000

----- Sample Output 1 ------
YES
NO
YES

----- explanation 1 ------
Test case 1: We can perform the following operation:
- Select $i = 3$ and $j = 5$. Then $10\underline{1}0\underline{1}1 \rightarrow 100001$, which is a palindrome.

Test case 2: It can be proven that we can not make $S$ a palindrome using the given operation.

Test case 3: We can perform the following operations:
- Select $i = 4$ and $j = 5$. Then $111\underline{0}\underline{0}00 \rightarrow 1111100$
- Select $i = 6$ and $j = 7$. Then $11111\underline{0}\underline{0} \rightarrow 1111111$, which is a palindrome.

输入格式

见题面

输出格式

见题面

样例输入
3 6 101011 2 01 7 1110000
样例输出
YES NO YES