CF2178B.Impost or Sus

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A string ww consisting of lowercase Latin letters is called suspicious if and only if all of the following conditions hold:

  • The letter s\mathtt{s} appears at least twice, and
  • For every occurrence of the letter u\mathtt{u}, the two nearest occurrences of s\mathtt{s} are the same number of characters away from the u\mathtt{u}.

After watching you finish a string task, your friend Aka has gifted you a string rr consisting only of letters s\mathtt{s} and u\mathtt{u}. You can perform the following operation on rr:

  • Choose an index ii (1≤i≤∣r∣1\le i\le |r|), and set rir_i to s\mathtt{s}.

Determine the minimum number of operations needed to make rr suspicious. It can be shown that, under the given constraints, it is always possible to transform rr into a suspicious string.

一个仅由小写拉丁字母组成的字符串 ww 被称为可疑的,当且仅当满足以下所有条件:

  • 字母 s\mathtt{s} 至少出现两次;且
  • 对于每一个字母 u\mathtt{u} 的出现位置,其左右两侧最近的两个 s\mathtt{s} 出现位置到该 u\mathtt{u} 的距离相等。

在目睹你完成一道字符串题目后,你的朋友 Aka 送给你一个仅由字母 s\mathtt{s} 和 u\mathtt{u} 组成的字符串 rr。你可以对 rr 执行如下操作:

  • 选择一个下标 ii(1≤i≤∣r∣1\le i\le |r|),并将 rir_i 修改为 s\mathtt{s}。

请确定使 rr 变为可疑字符串所需的最少操作次数。可以证明:在给定约束条件下,总能将 rr 变为一个可疑字符串。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The only line of each test case contains the string rr (3≤∣r∣≤2⋅1053\le |r|\le 2\cdot 10^5). It is guaranteed that ri=sr_i = \mathtt{s} or u\mathtt{u}.

It is guaranteed that the sum of ∣r∣|r| over all test cases does not exceed 2⋅1052\cdot 10 ^ 5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例仅一行,包含字符串 rr(3≤∣r∣≤2⋅1053\le |r|\le 2\cdot 10^5)。保证 rir_i 为字符 s\mathtt{s} 或 u\mathtt{u}。

保证所有测试用例的 ∣r∣|r| 之和不超过 2⋅1052\cdot 10 ^ 5。

输出格式

For each test case, output a single integer — the minimum number of operations needed to make rr suspicious.

对于每个测试用例,输出一个整数——使 rr 变为可疑所需的最少操作次数。

输入输出样例

  • 输入#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\mathtt{sus} is already suspicious because s\mathtt{s} appears twice in the string and the two nearest s\mathtt{s} to the only u\mathtt{u} are both 11 character away: su‾s\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}.

In the second test case, it is optimal to perform the operation on indices 11, 33, and 44. After that, the string ss becomes suss\texttt{suss}. The string suss\mathtt{suss} is suspicious because s\mathtt{s} appears 33 times in the string and the two nearest s\mathtt{s} to the only u\mathtt{u} are both 11 character away: su‾ss\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}\mathtt{s}.

In the third test case, the condition on u\mathtt{u} is vacuously true because there is no u\mathtt{u} in the string sssss\mathtt{sssss}. Thus, the given string is already suspicious.

In the sixth test case, the initial string usssssss\mathtt{usssssss} is not suspicious because the two nearest s\mathtt{s} to the only u\mathtt{u} are one and two characters away, respectively: u‾sssssss\underline{\mathtt{u}}\color{red}{\mathtt{ss}}\mathtt{sssss}.

在第一个测试用例中,字符串 sus\mathtt{sus} 已经是可疑的,因为 s\mathtt{s} 在该字符串中出现了两次,且唯一一个 u\mathtt{u} 的两个最近的 s\mathtt{s} 均相距 11 个字符:su‾s\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}。

在第二个测试用例中,最优操作是将下标 11、33 和 44 处的字符执行操作。操作后,字符串 ss 变为 suss\texttt{suss}。字符串 suss\mathtt{suss} 是可疑的,因为 s\mathtt{s} 在该字符串中出现了 33 次,且唯一一个 u\mathtt{u} 的两个最近的 s\mathtt{s} 均相距 11 个字符:su‾ss\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}\mathtt{s}。

在第三个测试用例中,关于 u\mathtt{u} 的条件自动成立(vacuously true),因为字符串 sssss\mathtt{sssss} 中不含任何 u\mathtt{u}。因此,给定字符串已经是可疑的。

在第六个测试用例中,初始字符串 usssssss\mathtt{usssssss} 并不满足可疑条件,因为唯一一个 u\mathtt{u} 的两个最近的 s\mathtt{s} 分别相距 11 个和 22 个字符:u‾sssssss\underline{\mathtt{u}}\color{red}{\mathtt{ss}}\mathtt{sssss}。

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

首页