#P14855. [ICPC 2021 Yokohama R] Reversible Compression
[ICPC 2021 Yokohama R] Reversible Compression
题目描述
Data compression is an essential technology in our information society. It is to encode a given string into a (preferably) more compact code string so that it can be stored and/or transferred efficiently.
You are asked to design a novel compression algorithm such that even a code string is reversed it can be decoded into the given string.
Currently, you are considering the following specification as a candidate.
- A given string is a sequence of decimal digits, namely, and .
- A code string is a sequence of code words, and a code word consists of two decimal digits and . So, a code string is a sequence of even number of decimal digits.
- A code string is decoded into a string by the following procedure. Here, for brevity, a decimal digit ( or ) is also treated as the single digit decimal integer it represents.
- while ( is not greater than ) {
3. if ( is zero) { output }
4. else if ( is zero) { do nothing }
5. else if ( is larger than the number of digits output so far) { raise an error }
6. else {
7. repeat times {
8. output the -th of the already output digits counted backwards
9. }
10. }
11. - }
For example, a code string is decoded into a string as follows:
- The first code word outputs .
- The second code word outputs .
- The first digit of the last code word means that the second digit in the already decoded digits, counted backwards, should be output. This should be repeated five times. For the first repetition, the decoded digits so far are and , and thus the second last digit is , which is output. For the second repetition, digits decoded so far are and , and the second last is , which is output. Repeating this three more times outputs and .
A sequence of code words that raises no error is a valid code string. A valid code string is said to be reversible when its reverse is also valid and both the original and its reverse are decoded into the same string.
For example, the code string is not reversible, because its reverse, , raises an error and thus is not valid. The code string is not reversible though its reverse is valid. It is decoded into , but its reverse is decoded into . On the other hand, is reversible, because this and its reverse, , are both decoded into .
You want to evaluate the performance of this compression method when applied to a variety of cases. Your task is to write a program that, for an arbitrary given digit string, finds the shortest reversible code string that is decoded into the given string.
输入格式
The input consists of a single line containing a non-empty string of decimal digits. The length of does not exceed .
输出格式
Output the shortest reversible code string that is decoded into . If there are multiple solutions with the same shortest length, output the earliest in the lexicographic order. Note that it is easily shown that a reversible code string always exists for any input string (e.g., see Sample Output 4).
00000000000000000
0015599100
0101010
000122221000
123123123123123123123123123123
01020336699993302010
123456789
010203040506070809908070605040302010