AT_arc224_e.ABC|AB|A
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string S consisting of A, B, and C.
You can perform the following operation zero or more times.
- Choose a substring (contiguous subsequence) of S that is
A,AB, orABC, and delete it. The remaining characters are concatenated, preserving their order.
Find the minimum possible length of S in the end.
T test cases are given; solve each of them.
给你一个仅由字符 A、B 和 C 组成的字符串 S。
你可以执行以下操作零次或多次:
- 选择 S 的一个子串(连续子序列),该子串为
A、AB或ABC,并将其删除。剩余字符按原顺序拼接。
求最终 S 的最小可能长度。
共给出 T 组测试数据,请对每组数据求解。
输入格式
The input is given from Standard Input in the following format, where casei denotes the i-th test case:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
S
输入从标准输入给出,格式如下,其中 casei 表示第 i 个测试用例:
T
case1
case2
⋮
caseT
每个测试用例的格式如下:
S
输出格式
Output T lines. The i-th line should contain the answer for the i-th test case.
输出 T 行。第 i 行应包含第 i 个测试用例的答案。
输入输出样例
输入#1
5 CAABCB B AAABBC AABBCC CABCCBCBAABCBBBAABAABACABBC
输出#1
1 1 0 1 7
说明/提示
Sample 1 Explanation:
This input contains five test cases.
For the first test case, we can perform the operations as follows, for example.
- Choose and delete the third through fifth characters of S=
CAABCB. After the operation, S becomesCAB. - Choose and delete the second through third characters of S=
CAB. After the operation, S becomesC. - No further operations can be performed. S=
Chas length 1, which is the minimum achievable.
Constraints
- T is an integer between 1 and 105, inclusive.
- S is a string consisting of
A,B, andCwith length between 1 and 106, inclusive. - The sum of ∣S∣ in each input is at most 106.
样例 1 解释:
该输入包含五个测试用例。
对于第一个测试用例,我们可以按如下方式执行操作(例如):
- 选择并删除 S=
CAABCB的第 3 至第 5 个字符。操作后,S 变为CAB。 - 选择并删除 S=
CAB的第 2 至第 3 个字符。操作后,S 变为C。 - 无法再执行任何操作。此时 S=
C的长度为 1,即所能达到的最小长度。
约束条件
- T 是一个介于 1 到 105(含)之间的整数。
- S 是一个仅由字符
A、B和C组成的字符串,其长度介于 1 到 106(含)之间。 - 所有输入中 ∣S∣ 的总和不超过 106。
输入解题思路,AI测评打分。不知道怎么写?