CF1594C.Make Them Equal

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Theofanis has a string s1s2…sns_1 s_2 \dots s_n and a character cc. He wants to make all characters of the string equal to cc using the minimum number of operations.

In one operation he can choose a number xx (1≤x≤n1 \le x \le n) and for every position ii, where ii is not divisible by xx, replace sis_i with cc.

Find the minimum number of operations required to make all the characters equal to cc and the xx-s that he should use in his operations.

西奥法尼斯有一个字符串 s1s2…sns_1 s_2 \dots s_n 和一个字符 cc。他希望用最少的操作次数,使字符串中所有字符都变为 cc。

在一次操作中,他可以选择一个数 xx(1≤x≤n1 \le x \le n),并对每个位置 ii(其中 ii 不能被 xx 整除),将 sis_i 替换为 cc。

请找出使所有字符都变为 cc 所需的最少操作次数,以及每次操作中应选取的 xx 值。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains the integer nn (3≤n≤3⋅1053 \le n \le 3 \cdot 10^5) and a lowercase Latin letter cc — the length of the string ss and the character the resulting string should consist of.

The second line of each test case contains a string ss of lowercase Latin letters — the initial string.

It is guaranteed that the sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含整数 nn(3≤n≤3⋅1053 \le n \le 3 \cdot 10^5)和一个小写拉丁字母 cc —— 分别表示字符串 ss 的长度,以及最终字符串应由该字符构成。

每个测试用例的第二行包含一个由小写拉丁字母组成的字符串 ss —— 初始字符串。

保证所有测试用例的 nn 之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, firstly print one integer mm — the minimum number of operations required to make all the characters equal to cc.

Next, print mm integers x1,x2,…,xmx_1, x_2, \dots, x_m (1≤xj≤n1 \le x_j \le n) — the xx-s that should be used in the order they are given.

It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.

对于每个测试用例,首先输出一个整数 mm —— 使所有字符均变为 cc 所需的最少操作次数。

接下来输出 mm 个整数 x1,x2,…,xmx_1, x_2, \dots, x_m(其中 1≤xj≤n1 \le x_j \le n)—— 按照给定顺序执行操作所使用的 xx 值。

在给定约束条件下,可以证明答案一定存在。若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    4 a
    aaaa
    4 a
    baaa
    4 b
    bzyx

    输出#1

    0
    1
    2
    2 
    2 3

说明/提示

Let's describe what happens in the third test case:

  1. x1=2x_1 = 2: we choose all positions that are not divisible by 22 and replace them, i. e. bzyx →\rightarrow bzbx;
  2. x2=3x_2 = 3: we choose all positions that are not divisible by 33 and replace them, i. e. bzbx →\rightarrow bbbb.

我们来描述第三个测试用例中发生的情况:

  1. x1=2x_1 = 2:我们选择所有不能被 22 整除的位置并进行替换,即 bzyx →\rightarrow bzbx;
  2. x2=3x_2 = 3:我们选择所有不能被 33 整除的位置并进行替换,即 bzbx →\rightarrow bbbb。

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

首页