CF1685B.Linguistics

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Alina has discovered a weird language, which contains only 44 words: A\texttt{A} , B\texttt{B} , AB\texttt{AB} , BA\texttt{BA} . It also turned out that there are no spaces in this language: a sentence is written by just concatenating its words into a single string.

Alina has found one such sentence ss and she is curious: is it possible that it consists of precisely aa words A\texttt{A} , bb words B\texttt{B} , cc words AB\texttt{AB} , and dd words BA\texttt{BA} ?

In other words, determine, if it's possible to concatenate these a+b+c+da+b+c+d words in some order so that the resulting string is ss . Each of the a+b+c+da+b+c+d words must be used exactly once in the concatenation, but you can choose the order in which they are concatenated.

输入格式

The first line of the input contains a single integer tt ( 1t1051 \le t \le 10^5 ) — the number of test cases. The description of the test cases follows.

The first line of each test case contains four integers aa , bb , cc , dd ( 0a,b,c,d21050\le a,b,c,d\le 2\cdot 10^5 ) — the number of times that words A\texttt{A} , B\texttt{B} , AB\texttt{AB} , BA\texttt{BA} respectively must be used in the sentence.

The second line contains the string ss ( ss consists only of the characters A\texttt{A} and B\texttt{B} , 1s21051\le |s| \le 2\cdot 10^5 , s=a+b+2c+2d|s|=a+b+2c+2d ) — the sentence. Notice that the condition s=a+b+2c+2d|s|=a+b+2c+2d (here s|s| denotes the length of the string ss ) is equivalent to the fact that ss is as long as the concatenation of the a+b+c+da+b+c+d words.

The sum of the lengths of ss over all test cases doesn't exceed 21052\cdot 10^5 .

输出格式

For each test case output YES\texttt{YES} if it is possible that the sentence ss consists of precisely aa words A\texttt{A} , bb words B\texttt{B} , cc words AB\texttt{AB} , and dd words BA\texttt{BA} , and NO\texttt{NO} otherwise. You can output each letter in any case.

输入输出样例

  • 输入#1

    8
    1 0 0 0
    B
    0 0 1 0
    AB
    1 1 0 1
    ABAB
    1 0 1 1
    ABAAB
    1 1 2 2
    BAABBABBAA
    1 1 2 3
    ABABABBAABAB
    2 3 5 4
    AABAABBABAAABABBABBBABB
    1 3 3 10
    BBABABABABBBABABABABABABAABABA

    输出#1

    NO
    YES
    YES
    YES
    YES
    YES
    NO
    YES

说明/提示

In the first test case, the sentence ss is B\texttt{B} . Clearly, it can't consist of a single word A\texttt{A} , so the answer is NO\texttt{NO} .

In the second test case, the sentence ss is AB\texttt{AB} , and it's possible that it consists of a single word AB\texttt{AB} , so the answer is YES\texttt{YES} .

In the third test case, the sentence ss is ABAB\texttt{ABAB} , and it's possible that it consists of one word A\texttt{A} , one word B\texttt{B} , and one word BA\texttt{BA} , as A+BA+B=ABAB\texttt{A} + \texttt{BA} + \texttt{B} = \texttt{ABAB} .

In the fourth test case, the sentence ss is ABAAB\texttt{ABAAB} , and it's possible that it consists of one word A\texttt{A} , one word AB\texttt{AB} , and one word BA\texttt{BA} , as A+BA+AB=ABAAB\texttt{A} + \texttt{BA} + \texttt{AB} = \texttt{ABAAB} .

In the fifth test case, the sentence ss is BAABBABBAA\texttt{BAABBABBAA} , and it's possible that it consists of one word A\texttt{A} , one word B\texttt{B} , two words AB\texttt{AB} , and two words BA\texttt{BA} , as BA+AB+B+AB+BA+A=BAABBABBAA\texttt{BA} + \texttt{AB} + \texttt{B} + \texttt{AB} + \texttt{BA} + \texttt{A}= \texttt{BAABBABBAA} .

首页