CF1329D.Dreamoon Likes Strings

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Dreamoon likes strings. Today he created a game about strings:

String s1,s2,…,sns_1, s_2, \ldots, s_n is beautiful if and only if for each 1≤i<n,si≠si+11 \le i \lt n, s_i \ne s_{i+1}.

Initially, Dreamoon has a string aa. In each step Dreamoon can choose a beautiful substring of aa and remove it. Then he should concatenate the remaining characters (in the same order).

Dreamoon wants to use the smallest number of steps to make aa empty. Please help Dreamoon, and print any sequence of the smallest number of steps to make aa empty.

Dreamoon 喜欢字符串。今天他设计了一个关于字符串的游戏:

当且仅当对每个 1≤i<n1 \le i \lt n 都有 si≠si+1s_i \ne s_{i+1} 时,字符串 s1,s2,…,sns_1, s_2, \ldots, s_n 被称为“优美的”。

初始时,Dreamoon 拥有一个字符串 aa。在每一步中,Dreamoon 可以选择 aa 的一个优美子串并将其删除;然后他需将剩余字符(保持原有顺序)拼接起来。

Dreamoon 希望用最少的步数将 aa 变为空字符串。请帮助 Dreamoon,输出任意一种达到最少步数的删除操作序列。

输入格式

The first line contains an integer tt (1≤t≤200 0001 \leq t \leq 200\,000), denoting the number of test cases in the input.

For each test case, there's one line with a non-empty string of lowercase Latin letters aa.

The total sum of lengths of strings in all test cases is at most 200 000200\,000.

第一行包含一个整数 tt(1≤t≤200 0001 \leq t \leq 200\,000),表示输入中测试用例的数量。

对于每个测试用例,有一行,包含一个非空的、由小写拉丁字母组成的字符串 aa。

所有测试用例中字符串长度的总和不超过 200 000200\,000。

输出格式

For each test case, in the first line, you should print mm: the smallest number of steps to make aa empty. Each of the following mm lines should contain two integers li,ril_i, r_i (1≤li≤ri≤∣a∣1 \leq l_i \leq r_i \leq |a|), denoting, that the ii-th step is removing the characters from index lil_i to rir_i in the current string. (indices are numbered starting from 11).

Note that after the deletion of the substring, indices of remaining characters may change, and rir_i should be at most the current length of aa.

If there are several possible solutions, you can print any.

对于每个测试用例,第一行应输出 mm:使字符串 aa 为空所需的最少操作步数。接下来的 mm 行每行应包含两个整数 li,ril_i, r_i(满足 1≤li≤ri≤∣a∣1 \leq l_i \leq r_i \leq |a|),表示第 ii 步操作为删除当前字符串中从索引 lil_i 到 rir_i 的所有字符(索引从 11 开始编号)。

注意:在子串被删除后,剩余字符的索引会发生变化,且 rir_i 应不超过当前字符串 aa 的长度。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    4
    aabbcc
    aaabbb
    aaa
    abacad

    输出#1

    3
    3 3
    2 4
    1 2
    3
    3 4
    2 3
    1 2
    3
    1 1
    1 1
    1 1
    1
    1 6

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

首页