AT_arc224_e.ABC|AB|A

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string SS consisting of A, B, and C.

You can perform the following operation zero or more times.

  • Choose a substring (contiguous subsequence) of SS that is A, AB, or ABC, and delete it. The remaining characters are concatenated, preserving their order.

Find the minimum possible length of SS in the end.

TT test cases are given; solve each of them.

给你一个仅由字符 A、B 和 C 组成的字符串 SS。

你可以执行以下操作零次或多次:

  • 选择 SS 的一个子串(连续子序列),该子串为 A、AB 或 ABC,并将其删除。剩余字符按原顺序拼接。

求最终 SS 的最小可能长度。

共给出 TT 组测试数据,请对每组数据求解。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

SS

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例的格式如下:

SS

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#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=S= CAABCB. After the operation, SS becomes CAB.
  • Choose and delete the second through third characters of S=S= CAB. After the operation, SS becomes C.
  • No further operations can be performed. S=S= C has length 11, which is the minimum achievable.

Constraints

  • TT is an integer between 11 and 10510^5, inclusive.
  • SS is a string consisting of A, B, and C with length between 11 and 10610^6, inclusive.
  • The sum of ∣S∣|S| in each input is at most 10610^6.

样例 1 解释:
该输入包含五个测试用例。

对于第一个测试用例,我们可以按如下方式执行操作(例如):

  • 选择并删除 S=S= CAABCB 的第 3 至第 5 个字符。操作后,SS 变为 CAB。
  • 选择并删除 S=S= CAB 的第 2 至第 3 个字符。操作后,SS 变为 C。
  • 无法再执行任何操作。此时 S=S= C 的长度为 11,即所能达到的最小长度。

约束条件

  • TT 是一个介于 11 到 10510^5(含)之间的整数。
  • SS 是一个仅由字符 A、B 和 C 组成的字符串,其长度介于 11 到 10610^6(含)之间。
  • 所有输入中 ∣S∣|S| 的总和不超过 10610^6。

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

首页