Codeforces Round 1082 (Div. 2)
B
ABAB Construction
Codeforces
1200
原题
← AC1 →
翻译中…

There is a string $T$ of length $n$, such that $T_i=$ 'a' for all odd $i$ and $T_i=$ 'b' for all even $i$.

翻译中…

One day, Bob generated a string $S$ with the following algorithm.

翻译中…
  1. Initialize $S$ to the empty string.
  2. Remove either the first letter or the last letter from $T$, and append it to $S$.
  3. If $T$ is empty, terminate and return the string $S$. Otherwise, go back to the second step.
翻译中…

Then, Bob wrote down the generated string $S$ on a note and forgot about it for a few years. The note was worn out when Bob found it, and someone might have secretly changed some letters. Of course, Bob wants to know if someone did alter the string!

翻译中…

You are given a string $X$ of length $n$, which consists of 'a', 'b', and '?'.

翻译中…

Please determine if there exists a string $A$ which satisfies the following conditions:

翻译中…
  • $|A|=n$;
  • $A_i$ is either 'a' or 'b' for all $1 \le i \le n$;
  • $A_i=X_i$ for all $1 \le i \le n$ such that $X_i$ is not '?';
  • The string $A$ can be generated from the algorithm described above.
翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 200\,000$).

翻译中…

The second line of each test case contains a string $X$ of length $n$, consisting of 'a', 'b', and '?'.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $200\,000$.

翻译中…

Output

翻译中…

If there is a string $A$ that satisfies all conditions, output "YES" on a separate line.

翻译中…

If there is no string $A$ that satisfies all conditions, output "NO" on a separate line.

翻译中…

You can output the answer in any case. For example, the strings "yEs", "yes", "Yes" will also be recognized as positive responses.

翻译中…

Note

翻译中…

For the second test case, the string "baaba" cannot be generated by the algorithm described above.

翻译中…

For the third test case, the string "abaab" can be generated by the algorithm described above:

翻译中…
  1. Initially, $T$ is "ababa" and $S$ is empty.
  2. Remove the first letter from $T$. $T$ becomes "baba" and $S$ becomes "a".
  3. Remove the first letter from $T$. $T$ becomes "aba" and $S$ becomes "ab".
  4. Remove the last letter from $T$. $T$ becomes "ab" and $S$ becomes "aba".
  5. Remove the first letter from $T$. $T$ becomes "b" and $S$ becomes "abaa".
  6. Remove the last letter from $T$. $T$ becomes empty and $S$ becomes "abaab".
翻译中…

样例

Input #1
4
5
ababa
5
baaba
5
?b?ab
6
aa?b?b
Output #1
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
2202B
时间限制
1 s
内存限制
256 MB
标签
动态规划
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。