CF1685B.Linguistics
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
阿丽娜发现了一种奇怪的语言,该语言仅包含 4 个单词:A、B、AB 和 BA。此外,这种语言中没有空格:一个句子通过将其所有单词直接连接成一个字符串来书写。
阿丽娜找到了这样一个句子 s,她很好奇:它是否恰好由 a 个单词 A、b 个单词 B、c 个单词 AB 和 d 个单词 BA 组成?
换言之,请判断:能否将这 a+b+c+d 个单词以某种顺序连接起来,使得最终得到的字符串恰好为 s?这 a+b+c+d 个单词必须全部且仅使用一次,但你可以自由选择它们的连接顺序。
输入格式
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.
输入的第一行包含一个整数 t(1≤t≤105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含四个整数 a、b、c、d(0≤a,b,c,d≤2⋅105),分别表示句子中必须使用的单词 A、B、AB、BA 的次数。
每个测试用例的第二行包含字符串 s(s 仅由字符 A 和 B 组成,1≤∣s∣≤2⋅105,且满足 ∣s∣=a+b+2c+2d),即该句子。注意:条件 ∣s∣=a+b+2c+2d(其中 ∣s∣ 表示字符串 s 的长度)等价于 s 的长度恰好等于这 a+b+c+d 个单词拼接后的总长度。
所有测试用例中字符串 s 的长度之和不超过 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.
对于每个测试用例,如果句子 s 恰好由 a 个单词 A、b 个单词 B、c 个单词 AB 和 d 个单词 BA 组成是可能的,则输出 YES;否则输出 NO。你可以以任意大小写形式输出每个字母。
输入输出样例
输入#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.
在第一个测试用例中,句子 s 为 B。显然,它无法由单个单词 A 构成,因此答案为 NO。
在第二个测试用例中,句子 s 为 AB,它有可能由单个单词 AB 构成,因此答案为 YES。
在第三个测试用例中,句子 s 为 ABAB,它有可能由一个单词 A、一个单词 B 和一个单词 BA 构成,因为 A+BA+B=ABAB。
在第四个测试用例中,句子 s 为 ABAAB,它有可能由一个单词 A、一个单词 AB 和一个单词 BA 构成,因为 A+BA+AB=ABAAB。
在第五个测试用例中,句子 s 为 BAABBABBAA,它有可能由一个单词 A、一个单词 B、两个单词 AB 和两个单词 BA 构成,因为 BA+AB+B+AB+BA+A=BAABBABBAA。
输入解题思路,AI测评打分。不知道怎么写?