CF1685B.Linguistics
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alina has discovered a weird language, which contains only 4 words: A , B , AB , 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 s and she is curious: is it possible that it consists of precisely a words A , b words B , c words AB , and d words BA ?
In other words, determine, if it's possible to concatenate these a+b+c+d words in some order so that the resulting string is s . Each of the a+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 t ( 1≤t≤105 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains four integers a , b , c , d ( 0≤a,b,c,d≤2⋅105 ) — the number of times that words A , B , AB , BA respectively must be used in the sentence.
The second line contains the string s ( s consists only of the characters A and B , 1≤∣s∣≤2⋅105 , ∣s∣=a+b+2c+2d ) — the sentence. Notice that the condition ∣s∣=a+b+2c+2d (here ∣s∣ denotes the length of the string s ) is equivalent to the fact that s is as long as the concatenation of the a+b+c+d words.
The sum of the lengths of s over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case output YES if it is possible that the sentence s consists of precisely a words A , b words B , c words AB , and d words BA , and 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 s is B . Clearly, it can't consist of a single word A , so the answer is NO .
In the second test case, the sentence s is AB , and it's possible that it consists of a single word AB , so the answer is YES .
In the third test case, the sentence s is ABAB , and it's possible that it consists of one word A , one word B , and one word BA , as A+BA+B=ABAB .
In the fourth test case, the sentence s is ABAAB , and it's possible that it consists of one word A , one word AB , and one word BA , as A+BA+AB=ABAAB .
In the fifth test case, the sentence s is BAABBABBAA , and it's possible that it consists of one word A , one word B , two words AB , and two words BA , as BA+AB+B+AB+BA+A=BAABBABBAA .