FPC25-027.Characterithmetic
Easy · 3 s · 256 MB
- icpc
- fpc
- 2025
While solving one problem after the other in your favourite programming contest (hopefully, the one you are at right now!), you are suddenly faced with an Alternative Arithmetic Problem for the Jury's Entertainment. In this problem, you are not calculating with numbers, but with strings.
For some arbitrary string and integer , we define ( times ) to be the string concatenated times. If can be written as for some other string , we say that is a divisor of . For example, the divisors of the string “abababab” are , , and , because this string can be written as either , or , or . Finally, we say that a string is indivisible if its only divisor is : for example, the string “abc” is indivisible.
You are given a string of length , that contains only the characters ‘a’, ‘b’, and ‘c’. For each divisor of , you need to change some of the characters (to either ‘a’, ‘b’, or ‘c’), so that the largest divisor of becomes . Find the minimum number of characters that need to be changed in order to make this true.
As an example, consider the first sample input. There are three answers, one for each of the divisors of :
• To make the largest divisor of “acac” be , we need to make sure that is not a divisor. We can change any character to make the string indivisible, e.g. “bcac”.
• The largest divisor of “acac” is already , so no characters need to change and the answer is .
• To make the largest divisor , we need to make all characters equal. To do this, characters need to be changed, yielding either “aaaa” or “cccc”.
Giriş formatı
The input consists of:
• One line with an integer (), the length of your string.
• One line with a string of length , consisting only of characters ‘a’, ‘b’, and ‘c’.
Çıxış formatı
For each divisor of , in increasing order, output the minimum number of characters that you need to change to make the largest divisor of equal to .
Qeyd
Source: Freshmen Programming Contest 2025 · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 45 of the 165 original test cases (the largest) are omitted here to keep the problem lightweight.
Nümunələr
Giriş #1
4 acac
Çıxış #1
1 0 2
Giriş #2
6 abccba
Çıxış #2
0 2 4 4