codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1594C.md (1941B)


      1 Source: https://codeforces.com/problemset/problem/1594/C
      2 
      3 C. Make Them Equal
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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$.
     24 
     25 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.
     26 
     27 Input
     28 
     29 The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
     30 
     31 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.
     32 
     33 The second line of each test case contains a string $s$ of lowercase Latin letters — the initial string.
     34 
     35 It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
     36 
     37 Output
     38 
     39 For each test case, firstly print one integer $m$ — the minimum number of operations required to make all the characters equal to $c$.
     40 
     41 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.
     42 
     43 It can be proved that under given constraints, an answer always exists. If there are multiple answers, print any.
     44 
     45 Example
     46 
     47 Input
     48 
     49 ```
     50 3
     51 4 a
     52 aaaa
     53 4 a
     54 baaa
     55 4 b
     56 bzyx
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 0
     63 1
     64 2
     65 2 
     66 2 3
     67 ```
     68 
     69 Note
     70 
     71 Let's describe what happens in the third test case:
     72 
     73 1. $x_1 = 2$: we choose all positions that are not divisible by $2$ and replace them, i. e. bzyx $\rightarrow$ bzbx;
     74 2. $x_2 = 3$: we choose all positions that are not divisible by $3$ and replace them, i. e. bzbx $\rightarrow$ bbbb.