What is the most tedious part of running a contest?
Time limit1sMemory limit1024 MB
Build S by typing single characters or pasting one copied prefix of S, minimizing typed characters first and total actions second.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String matching, String
- Solved
- No attempts yet
Problem
The editorial does not have much work, but it is very tedious because it has to be done after the contest. This is especially true for MatKor Cup, which takes more than a semester to prepare.
MatKor began in spring 2022 under the name Donguisuhak (Dongu's math class). At that time it only held seminars, and MatKor Cup explained solutions in seminar form without an editorial. After it switched to an open contest, the editorial became extremely tedious work for Dongu.
MatKor Cup editorials are known for coming out very late. Each problem setter writes their editorial late, and Dongu's merging of the editorials is slower still. Now Dongu wants to start writing the editorial, but typing the string is too tedious! To minimize typing, Dongu wants to press ctrl + a and ctrl + c once, then keep using ctrl + v.
Dongu starts with an empty string. To write , Dongu can perform the following actions.
- Action
1: Type the character after the current string. This adds 1 to the fatigue. - Action
2- If the string has not been copied yet, copy the entire current string with
ctrl + a,ctrl + c. - If the string has already been copied, paste the copied string after the current string with
ctrl + v.
- If the string has not been copied yet, copy the entire current string with
Dongu wants the fatigue to be as small as possible. If several action sequences reach the minimum fatigue, Dongu wants the fewest actions. Help Dongu find such a sequence.
Input
The first line contains a string of lowercase English letters ().
Output
The first line prints the minimum fatigue and the minimum number of actions among sequences with minimum fatigue.
The second line prints a string of characters made of 1s and 2s. Performing the actions in this order must produce . If several strings are possible, print any one of them.