A14605 | Make Them Equal
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Theofanis has a string $s_1 s_2 \dots s_n$ 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 \le x \le n$ ) and for every position $i$ , where $i$ is not divisible by $x$ , replace $s_i$ 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.
In one operation he can choose a number $x$ ( $1 \le x \le n$ ) and for every position $i$ , where $i$ is not divisible by $x$ , replace $s_i$ 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.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
The first line of each test case contains the integer $n$ ( $3 \le n \le 3 \cdot 10^5$ ) 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 \cdot 10^5$ .
The first line of each test case contains the integer $n$ ( $3 \le n \le 3 \cdot 10^5$ ) 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 \cdot 10^5$ .
输出格式
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 $x_1, x_2, \dots, x_m$ ( $1 \le x_j \le 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.
Next, print $m$ integers $x_1, x_2, \dots, x_m$ ( $1 \le x_j \le 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.
输入输出样例
输入 #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. $x_1 = 2$ : we choose all positions that are not divisible by $2$ and replace them, i. e. bzyx $\rightarrow$ bzbx;
2. $x_2 = 3$ : we choose all positions that are not divisible by $3$ and replace them, i. e. bzbx $\rightarrow$ bbbb.
1. $x_1 = 2$ : we choose all positions that are not divisible by $2$ and replace them, i. e. bzyx $\rightarrow$ bzbx;
2. $x_2 = 3$ : we choose all positions that are not divisible by $3$ and replace them, i. e. bzbx $\rightarrow$ bbbb.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted