309473: CF1685B. Linguistics

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Linguistics

题意翻译

Alina 发现了一种只由 $\text{A, B, AB, BA}$ 四种单词组成的语言,这种语言不含有空格,书写句子时只需要将单词直接连接起来即可。 她很好奇是否可以用 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 拼接形成句子 $s$。 换句话说,是否可以用 $a+b+c+d$ 个单词以某种顺序拼接出句子 $s$,这 $a+b+c+d$ 个单词都得被用到,他们的顺序可以由你决定。 **【输入格式】** 第一行是一个数字 $t$,表示数据的组数。每一组的格式如下: 每组的第一行是四个数字 $a, b, c, d$($0\leq a,b,c,d\leq2\cdot10^5$),它们分别代表本组单词 $\text{A, B, AB, BA}$ 需要使用的次数。 每组的第二行是一个字符串 $s$($|s|\leq 2\cdot 10^5$),并且保证 $s$ 的总长和 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 拼接形成的长度相同($|s|=a+b+2c+2d$)。其中 $|s|$ 表示字符串 $s$ 的长度。 所有 $s$ 的总长度之和不会超过 $2\cdot 10^5$。 **【输出格式】** 对于每组数据,如果该组数据的 $s$ 可以被 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 不限顺序地拼接形成,那么输出一个字符串 `YES`,否则输出 `NO`。

题目描述

Alina has discovered a weird language, which contains only $ 4 $ words: $ \texttt{A} $ , $ \texttt{B} $ , $ \texttt{AB} $ , $ \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 $ s $ and she is curious: is it possible that it consists of precisely $ a $ words $ \texttt{A} $ , $ b $ words $ \texttt{B} $ , $ c $ words $ \texttt{AB} $ , and $ d $ words $ \texttt{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 \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 $ a $ , $ b $ , $ c $ , $ d $ ( $ 0\le a,b,c,d\le 2\cdot 10^5 $ ) — the number of times that words $ \texttt{A} $ , $ \texttt{B} $ , $ \texttt{AB} $ , $ \texttt{BA} $ respectively must be used in the sentence. The second line contains the string $ s $ ( $ s $ consists only of the characters $ \texttt{A} $ and $ \texttt{B} $ , $ 1\le |s| \le 2\cdot 10^5 $ , $ |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\cdot 10^5 $ .

输出格式


For each test case output $ \texttt{YES} $ if it is possible that the sentence $ s $ consists of precisely $ a $ words $ \texttt{A} $ , $ b $ words $ \texttt{B} $ , $ c $ words $ \texttt{AB} $ , and $ d $ words $ \texttt{BA} $ , and $ \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 $ s $ is $ \texttt{B} $ . Clearly, it can't consist of a single word $ \texttt{A} $ , so the answer is $ \texttt{NO} $ . In the second test case, the sentence $ s $ is $ \texttt{AB} $ , and it's possible that it consists of a single word $ \texttt{AB} $ , so the answer is $ \texttt{YES} $ . In the third test case, the sentence $ s $ is $ \texttt{ABAB} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{B} $ , and one word $ \texttt{BA} $ , as $ \texttt{A} + \texttt{BA} + \texttt{B} = \texttt{ABAB} $ . In the fourth test case, the sentence $ s $ is $ \texttt{ABAAB} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{AB} $ , and one word $ \texttt{BA} $ , as $ \texttt{A} + \texttt{BA} + \texttt{AB} = \texttt{ABAAB} $ . In the fifth test case, the sentence $ s $ is $ \texttt{BAABBABBAA} $ , and it's possible that it consists of one word $ \texttt{A} $ , one word $ \texttt{B} $ , two words $ \texttt{AB} $ , and two words $ \texttt{BA} $ , as $ \texttt{BA} + \texttt{AB} + \texttt{B} + \texttt{AB} + \texttt{BA} + \texttt{A}= \texttt{BAABBABBAA} $ .

Input

题意翻译

Alina 发现了一种只由 $\text{A, B, AB, BA}$ 四种单词组成的语言,这种语言不含有空格,书写句子时只需要将单词直接连接起来即可。 她很好奇是否可以用 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 拼接形成句子 $s$。 换句话说,是否可以用 $a+b+c+d$ 个单词以某种顺序拼接出句子 $s$,这 $a+b+c+d$ 个单词都得被用到,他们的顺序可以由你决定。 **【输入格式】** 第一行是一个数字 $t$,表示数据的组数。每一组的格式如下: 每组的第一行是四个数字 $a, b, c, d$($0\leq a,b,c,d\leq2\cdot10^5$),它们分别代表本组单词 $\text{A, B, AB, BA}$ 需要使用的次数。 每组的第二行是一个字符串 $s$($|s|\leq 2\cdot 10^5$),并且保证 $s$ 的总长和 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 拼接形成的长度相同($|s|=a+b+2c+2d$)。其中 $|s|$ 表示字符串 $s$ 的长度。 所有 $s$ 的总长度之和不会超过 $2\cdot 10^5$。 **【输出格式】** 对于每组数据,如果该组数据的 $s$ 可以被 $a$ 个 $\text{A}$,$b$ 个 $\text{B}$,$c$ 个 $\text{AB}$,$d$ 个 $\text{BA}$ 不限顺序地拼接形成,那么输出一个字符串 `YES`,否则输出 `NO`。

Output

**题意翻译**

Alina 发现了一种只由 A, B, AB, BA 四种单词组成的语言,这种语言不含有空格,书写句子时只需要将单词直接连接起来即可。

她很好奇是否可以用 a 个 A,b 个 B,c 个 AB,d 个 BA 拼接形成句子 s。

换句话说,是否可以用 a+b+c+d 个单词以某种顺序拼接出句子 s,这 a+b+c+d 个单词都得被用到,他们的顺序可以由你决定。

**【输入格式】**

第一行是一个数字 t,表示数据的组数。每一组的格式如下:

每组的第一行是四个数字 a, b, c, d(0≤a,b,c,d≤2×10^5),它们分别代表本组单词 A, B, AB, BA 需要使用的次数。
每组的第二行是一个字符串 s(|s|≤2×10^5),并且保证 s 的总长和 a 个 A,b 个 B,c 个 AB,d 个 BA 拼接形成的长度相同(|s|=a+b+2c+2d)。其中 |s| 表示字符串 s 的长度。

所有 s 的总长度之和不会超过 2×10^5。

**【输出格式】**

对于每组数据,如果该组数据的 s 可以被 a 个 A,b 个 B,c 个 AB,d 个 BA 不限顺序地拼接形成,那么输出一个字符串 `YES`,否则输出 `NO`。

---

**题目描述**

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≤10^5) — 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×10^5) — 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×10^5, |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×10^5.

**输出格式**

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**题意翻译** Alina 发现了一种只由 A, B, AB, BA 四种单词组成的语言,这种语言不含有空格,书写句子时只需要将单词直接连接起来即可。 她很好奇是否可以用 a 个 A,b 个 B,c 个 AB,d 个 BA 拼接形成句子 s。 换句话说,是否可以用 a+b+c+d 个单词以某种顺序拼接出句子 s,这 a+b+c+d 个单词都得被用到,他们的顺序可以由你决定。 **【输入格式】** 第一行是一个数字 t,表示数据的组数。每一组的格式如下: 每组的第一行是四个数字 a, b, c, d(0≤a,b,c,d≤2×10^5),它们分别代表本组单词 A, B, AB, BA 需要使用的次数。 每组的第二行是一个字符串 s(|s|≤2×10^5),并且保证 s 的总长和 a 个 A,b 个 B,c 个 AB,d 个 BA 拼接形成的长度相同(|s|=a+b+2c+2d)。其中 |s| 表示字符串 s 的长度。 所有 s 的总长度之和不会超过 2×10^5。 **【输出格式】** 对于每组数据,如果该组数据的 s 可以被 a 个 A,b 个 B,c 个 AB,d 个 BA 不限顺序地拼接形成,那么输出一个字符串 `YES`,否则输出 `NO`。 --- **题目描述** 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≤10^5) — 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×10^5) — 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×10^5, |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×10^5. **输出格式** 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

加入题单

上一题 下一题 算法标签: