CF1873G.ABBC or BACB
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s made up of characters A and B. Initially you have no coins. You can perform two types of operations:
- Pick a substring† AB, change it to BC, and get a coin.
- Pick a substring† BA, change it to CB, and get a coin.
What is the most number of coins you can obtain?
† A substring of length 2 is a sequence of two adjacent characters of a string.
给你一个仅由字符 A 和 B 构成的字符串 s。初始时你没有硬币。你可以执行以下两种操作:
- 选取一个子串† AB,将其改为 BC,并获得一枚硬币;
- 选取一个子串† BA,将其改为 CB,并获得一枚硬币。
你最多能获得多少枚硬币?
† 长度为 2 的子串是指字符串中两个相邻的字符所组成的序列。
输入格式
The input consists of multiple test cases. The first line of the input contains a single integer t (1≤t≤1000) — the number of test cases.
The only line of each test case contains the string s (1≤∣s∣≤2⋅105). All characters of s are either A or B.
The sum of the lengths of s over all test cases does not exceed 2⋅105.
输入包含多个测试用例。输入的第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
每个测试用例仅有一行,包含字符串 s(1≤∣s∣≤2⋅105)。字符串 s 中的所有字符均为 A 或 B。
所有测试用例中字符串 s 的长度总和不超过 2⋅105。
输出格式
For each test case, output a single integer — the maximum number of coins you can obtain.
对于每个测试用例,输出一个整数——你能获得的最多硬币数量。
输入输出样例
输入#1
8 ABBA ABA BAABA ABB AAAAAAB BABA B AAA
输出#1
2 1 3 1 6 2 0 0
说明/提示
In the first test case you can perform the following operations to get 2 coins: $$\color{red}{\texttt{AB}}\texttt{BA} \to \texttt{BC}\color{red}{\texttt{BA}} \to \texttt{BCCB}$$
In the second test case you can perform the following operation to get 1 coin: $$\color{red}{\texttt{AB}}\texttt{A} \to \texttt{BCA}$$
In the third test case you can perform the following operations to get 3 coins: $$\color{red}{\texttt{BA}}\texttt{ABA} \to \texttt{CBA}\color{red}{\texttt{BA}} \to \texttt{C}\color{red}{\texttt{BA}}\texttt{CB} \to \texttt{CCBCB}$$
在第一个测试用例中,你可以执行以下操作来获得 2 枚硬币:
ABBA→BCBA→BCCB
在第二个测试用例中,你可以执行以下操作来获得 1 枚硬币:
ABA→BCA
在第三个测试用例中,你可以执行以下操作来获得 3 枚硬币:
BAABA→CBABA→CBACB→CCBCB
输入解题思路,AI测评打分。不知道怎么写?