CF1672B.I love AAAB
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's call a string good if its length is at least 2 and all of its characters are A except for the last character which is B. The good strings are AB,AAB,AAAB,…. Note that B is not a good string.
You are given an initially empty string s1.
You can perform the following operation any number of times:
- Choose any position of s1 and insert some good string in that position.
Given a string s2, can we turn s1 into s2 after some number of operations?
我们称一个字符串是“好”的,当且仅当其长度至少为 2,且除最后一个字符为 B 外,其余所有字符均为 A。因此,所有“好”字符串形如 AB,AAB,AAAB,…。注意:B 本身不是“好”字符串。
给定一个初始为空的字符串 s1。
你可以执行以下操作任意多次:
- 任选 s1 中的一个位置,并在该位置插入某个“好”字符串。
给定一个字符串 s2,能否通过若干次上述操作将 s1 变为 s2?
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single string s2 (1≤∣s2∣≤2⋅105).
It is guaranteed that s2 consists of only the characters A and B.
It is guaranteed that the sum of ∣s2∣ over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个字符串 s2(1≤∣s2∣≤2⋅105)。
保证 s2 仅由字符 A 和 B 组成。
保证所有测试用例的 ∣s2∣ 之和不超过 2⋅105。
输出格式
For each test case, print "YES" (without quotes) if we can turn s1 into s2 after some number of operations, and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
对于每个测试用例,如果经过若干次操作后可以将 s1 变为 s2,则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。
你可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 "yEs"、"yes" 和 "Yes" 均会被识别为肯定回答)。
输入输出样例
输入#1
4 AABAB ABB AAAAAAAAB A
输出#1
YES NO YES NO
说明/提示
In the first test case, we transform s1 as such: ∅→AAB→AABAB.
In the third test case, we transform s1 as such: ∅→AAAAAAAAB.
In the second and fourth test case, it can be shown that it is impossible to turn s1 into s2.
在第一个测试用例中,我们对 s1 进行如下变换:∅→AAB→AABAB。
在第三个测试用例中,我们对 s1 进行如下变换:∅→AAAAAAAAB。
在第二个和第四个测试用例中,可以证明无法将 s1 变为 s2。
输入解题思路,AI测评打分。不知道怎么写?