CF2178B.Impost or Sus
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A string w consisting of lowercase Latin letters is called suspicious if and only if all of the following conditions hold:
- The letter s appears at least twice, and
- For every occurrence of the letter u, the two nearest occurrences of s are the same number of characters away from the u.
After watching you finish a string task, your friend Aka has gifted you a string r consisting only of letters s and u. You can perform the following operation on r:
- Choose an index i (1≤i≤∣r∣), and set ri to s.
Determine the minimum number of operations needed to make r suspicious. It can be shown that, under the given constraints, it is always possible to transform r into a suspicious string.
一个仅由小写拉丁字母组成的字符串 w 被称为可疑的,当且仅当满足以下所有条件:
- 字母 s 至少出现两次;且
- 对于每一个字母 u 的出现位置,其左右两侧最近的两个 s 出现位置到该 u 的距离相等。
在目睹你完成一道字符串题目后,你的朋友 Aka 送给你一个仅由字母 s 和 u 组成的字符串 r。你可以对 r 执行如下操作:
- 选择一个下标 i(1≤i≤∣r∣),并将 ri 修改为 s。
请确定使 r 变为可疑字符串所需的最少操作次数。可以证明:在给定约束条件下,总能将 r 变为一个可疑字符串。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The only line of each test case contains the string r (3≤∣r∣≤2⋅105). It is guaranteed that ri=s or u.
It is guaranteed that the sum of ∣r∣ over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例仅一行,包含字符串 r(3≤∣r∣≤2⋅105)。保证 ri 为字符 s 或 u。
保证所有测试用例的 ∣r∣ 之和不超过 2⋅105。
输出格式
For each test case, output a single integer — the minimum number of operations needed to make r suspicious.
对于每个测试用例,输出一个整数——使 r 变为可疑所需的最少操作次数。
输入输出样例
输入#1
9 sus uuuu sssss uusuuu suuuuuu usssssss sssuuusss susuusuuus uuuuuuuuuuu
输出#1
0 3 0 3 3 1 1 2 6
说明/提示
In the first test case, the string sus is already suspicious because s appears twice in the string and the two nearest s to the only u are both 1 character away: sus.
In the second test case, it is optimal to perform the operation on indices 1, 3, and 4. After that, the string s becomes suss. The string suss is suspicious because s appears 3 times in the string and the two nearest s to the only u are both 1 character away: suss.
In the third test case, the condition on u is vacuously true because there is no u in the string sssss. Thus, the given string is already suspicious.
In the sixth test case, the initial string usssssss is not suspicious because the two nearest s to the only u are one and two characters away, respectively: usssssss.
在第一个测试用例中,字符串 sus 已经是可疑的,因为 s 在该字符串中出现了两次,且唯一一个 u 的两个最近的 s 均相距 1 个字符:sus。
在第二个测试用例中,最优操作是将下标 1、3 和 4 处的字符执行操作。操作后,字符串 s 变为 suss。字符串 suss 是可疑的,因为 s 在该字符串中出现了 3 次,且唯一一个 u 的两个最近的 s 均相距 1 个字符:suss。
在第三个测试用例中,关于 u 的条件自动成立(vacuously true),因为字符串 sssss 中不含任何 u。因此,给定字符串已经是可疑的。
在第六个测试用例中,初始字符串 usssssss 并不满足可疑条件,因为唯一一个 u 的两个最近的 s 分别相距 1 个和 2 个字符:usssssss。
输入解题思路,AI测评打分。不知道怎么写?