CF1594C.Make Them Equal
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Theofanis has a string s1s2…sn and a character c. He wants to make all characters of the string equal to c using the minimum number of operations.
In one operation he can choose a number x (1≤x≤n) and for every position i, where i is not divisible by x, replace si with c.
Find the minimum number of operations required to make all the characters equal to c and the x-s that he should use in his operations.
西奥法尼斯有一个字符串 s1s2…sn 和一个字符 c。他希望用最少的操作次数,使字符串中所有字符都变为 c。
在一次操作中,他可以选择一个数 x(1≤x≤n),并对每个位置 i(其中 i 不能被 x 整除),将 si 替换为 c。
请找出使所有字符都变为 c 所需的最少操作次数,以及每次操作中应选取的 x 值。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains the integer n (3≤n≤3⋅105) and a lowercase Latin letter c — the length of the string s and the character the resulting string should consist of.
The second line of each test case contains a string s of lowercase Latin letters — the initial string.
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含整数 n(3≤n≤3⋅105)和一个小写拉丁字母 c —— 分别表示字符串 s 的长度,以及最终字符串应由该字符构成。
每个测试用例的第二行包含一个由小写拉丁字母组成的字符串 s —— 初始字符串。
保证所有测试用例的 n 之和不超过 3⋅105。
输出格式
For each test case, firstly print one integer m — the minimum number of operations required to make all the characters equal to c.
Next, print m integers x1,x2,…,xm (1≤xj≤n) — the x-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.
对于每个测试用例,首先输出一个整数 m —— 使所有字符均变为 c 所需的最少操作次数。
接下来输出 m 个整数 x1,x2,…,xm(其中 1≤xj≤n)—— 按照给定顺序执行操作所使用的 x 值。
在给定约束条件下,可以证明答案一定存在。若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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:
- x1=2: we choose all positions that are not divisible by 2 and replace them, i. e. bzyx → bzbx;
- x2=3: we choose all positions that are not divisible by 3 and replace them, i. e. bzbx → bbbb.
我们来描述第三个测试用例中发生的情况:
- x1=2:我们选择所有不能被 2 整除的位置并进行替换,即 bzyx → bzbx;
- x2=3:我们选择所有不能被 3 整除的位置并进行替换,即 bzbx → bbbb。
输入解题思路,AI测评打分。不知道怎么写?