Make Them Equal solution codeforces
-
For Solution
Click Here!
Theofanis has a string s1s2…sns1s2…sn 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≤x≤n) and for every position ii, where ii is not divisible by xx, replace sisi 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.
Make Them Equal solution codeforces
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.
The first line of each test case contains the integer nn (3≤n≤3⋅1053≤n≤3⋅105) 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⋅105.
Make Them Equal solution codeforces
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,…,xmx1,x2,…,xm (1≤xj≤n1≤xj≤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.
input
Make Them Equal solution codeforces
3 4 a aaaa 4 a baaa 4 b bzyx
Make Them Equal solution codeforces
0 1 2 2 2 3
Let’s describe what happens in the third test case:
- x1=2x1=2: we choose all positions that are not divisible by 22 and replace them, i. e. bzyx →→ bzbx;
- x2=3x2=3: we choose all positions that are not divisible by 33 and replace them, i. e. bzbx →→ bbbb.
-
For Solution
Click Here!