CF1669D.Colorful Stamp

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A row of nn cells is given, all initially white. Using a stamp, you can stamp any two neighboring cells such that one becomes red and the other becomes blue. A stamp can be rotated, i.e. it can be used in both ways: as BR\color{blue}{\texttt{B}}\color{red}{\texttt{R}} and as RB\color{red}{\texttt{R}}\color{blue}{\texttt{B}} .

During use, the stamp must completely fit on the given nn cells (it cannot be partially outside the cells). The stamp can be applied multiple times to the same cell. Each usage of the stamp recolors both cells that are under the stamp.

For example, one possible sequence of stamps to make the picture BRBBW\color{blue}{\texttt{B}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\color{blue}{\texttt{B}}\texttt{W} could be WWWWWWWRBWBRRBWBRBBW\texttt{WWWWW} \to \texttt{WW}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\texttt{W} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{red}{\texttt{R}}\color{blue}{\texttt{B}}\texttt{W} \to \color{blue}{\texttt{B}}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}}\texttt{W} . Here W\texttt{W} , R\color{red}{\texttt{R}} , and B\color{blue}{\texttt{B}} represent a white, red, or blue cell, respectively, and the cells that the stamp is used on are marked with an underline.

Given a final picture, is it possible to make it using the stamp zero or more times?

输入格式

The first line contains an integer tt ( 1t1041 \leq t \leq 10^4 ) — the number of test cases.

The first line of each test case contains an integer nn ( 1n1051 \leq n \leq 10^5 ) — the length of the picture.

The second line of each test case contains a string ss — the picture you need to make. It is guaranteed that the length of ss is nn and that ss only consists of the characters W\texttt{W} , R\texttt{R} , and B\texttt{B} , representing a white, red, or blue cell, respectively.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

Output tt lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if it possible to make the picture using the stamp zero or more times, and "NO" 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

    12
    5
    BRBBW
    1
    B
    2
    WB
    2
    RW
    3
    BRB
    3
    RBB
    7
    WWWWWWW
    9
    RBWBWRRBW
    10
    BRBRBRBRRB
    12
    BBBRWWRRRWBR
    10
    BRBRBRBRBW
    5
    RBWBW

    输出#1

    YES
    NO
    NO
    NO
    YES
    YES
    YES
    NO
    YES
    NO
    YES
    NO

说明/提示

The first test case is explained in the statement.

For the second, third, and fourth test cases, it is not possible to stamp a single cell, so the answer is "NO".

For the fifth test case, you can use the stamp as follows: WWWWRBBRB\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{blue}{\texttt{B}}\color{red}{\texttt{R}}}}\color{blue}{\texttt{B}} .

For the sixth test case, you can use the stamp as follows: WWWWRBRBB\texttt{WWW} \to \texttt{W}\color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}} \to \color{brown}{\underline{\color{red}{\texttt{R}}\color{blue}{\texttt{B}}}}\color{blue}{\texttt{B}} .

For the seventh test case, you don't need to use the stamp at all.

首页