CF1685B.Linguistics

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

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.

阿丽娜发现了一种奇怪的语言,该语言仅包含 44 个单词:A\texttt{A}、B\texttt{B}、AB\texttt{AB} 和 BA\texttt{BA}。此外,这种语言中没有空格:一个句子通过将其所有单词直接连接成一个字符串来书写。

阿丽娜找到了这样一个句子 ss,她很好奇:它是否恰好由 aa 个单词 A\texttt{A}、bb 个单词 B\texttt{B}、cc 个单词 AB\texttt{AB} 和 dd 个单词 BA\texttt{BA} 组成?

换言之,请判断:能否将这 a+b+c+da+b+c+d 个单词以某种顺序连接起来,使得最终得到的字符串恰好为 ss?这 a+b+c+da+b+c+d 个单词必须全部且仅使用一次,但你可以自由选择它们的连接顺序。

输入格式

The first line of the input contains a single integer tt (1≤t≤1051 \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 (0≤a,b,c,d≤2⋅1050\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}, 1≤∣s∣≤2⋅1051\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 2⋅1052\cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1051 \le t \le 10^5),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含四个整数 aa、bb、cc、dd(0≤a,b,c,d≤2⋅1050\le a,b,c,d\le 2\cdot 10^5),分别表示句子中必须使用的单词 A\texttt{A}、B\texttt{B}、AB\texttt{AB}、BA\texttt{BA} 的次数。

每个测试用例的第二行包含字符串 ss(ss 仅由字符 A\texttt{A} 和 B\texttt{B} 组成,1≤∣s∣≤2⋅1051\le |s| \le 2\cdot 10^5,且满足 ∣s∣=a+b+2c+2d|s|=a+b+2c+2d),即该句子。注意:条件 ∣s∣=a+b+2c+2d|s|=a+b+2c+2d(其中 ∣s∣|s| 表示字符串 ss 的长度)等价于 ss 的长度恰好等于这 a+b+c+da+b+c+d 个单词拼接后的总长度。

所有测试用例中字符串 ss 的长度之和不超过 2⋅1052\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.

对于每个测试用例,如果句子 ss 恰好由 aa 个单词 A\texttt{A}、bb 个单词 B\texttt{B}、cc 个单词 AB\texttt{AB} 和 dd 个单词 BA\texttt{BA} 组成是可能的,则输出 YES\texttt{YES};否则输出 NO\texttt{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 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}.

在第一个测试用例中,句子 ss 为 B\texttt{B}。显然,它无法由单个单词 A\texttt{A} 构成,因此答案为 NO\texttt{NO}。

在第二个测试用例中,句子 ss 为 AB\texttt{AB},它有可能由单个单词 AB\texttt{AB} 构成,因此答案为 YES\texttt{YES}。

在第三个测试用例中,句子 ss 为 ABAB\texttt{ABAB},它有可能由一个单词 A\texttt{A}、一个单词 B\texttt{B} 和一个单词 BA\texttt{BA} 构成,因为 A+BA+B=ABAB\texttt{A} + \texttt{BA} + \texttt{B} = \texttt{ABAB}。

在第四个测试用例中,句子 ss 为 ABAAB\texttt{ABAAB},它有可能由一个单词 A\texttt{A}、一个单词 AB\texttt{AB} 和一个单词 BA\texttt{BA} 构成,因为 A+BA+AB=ABAAB\texttt{A} + \texttt{BA} + \texttt{AB} = \texttt{ABAAB}。

在第五个测试用例中,句子 ss 为 BAABBABBAA\texttt{BAABBABBAA},它有可能由一个单词 A\texttt{A}、一个单词 B\texttt{B}、两个单词 AB\texttt{AB} 和两个单词 BA\texttt{BA} 构成,因为 BA+AB+B+AB+BA+A=BAABBABBAA\texttt{BA} + \texttt{AB} + \texttt{B} + \texttt{AB} + \texttt{BA} + \texttt{A}= \texttt{BAABBABBAA}。

输入解题思路,AI测评打分。不知道怎么写?

首页