#P5794. [THUSC 2015] 解密运算
[THUSC 2015] 解密运算
Description
For a string of length , we append a special character . to the end of the string. Then we treat the string as a cycle. Starting from positions , read characters each time, and we can obtain strings.
For example, for the string ABCAAA, we can get these strings:
ABCAAA.
BCAAA.A
CAAA.AB
AAA.ABC
AA.ABCA
A.ABCAA
.ABCAAA
Next, we sort these strings in lexicographical order from small to large (note that the special character . is lexicographically smaller than any other character). The result is:
.ABCAAA
A.ABCAA
AA.ABCA
AAA.ABC
ABCAAA.
BCAAA.A
CAAA.AB
Finally, take the last character of each of the sorted strings, and concatenate them in order into a new string. That is, the last column of the table above, which is the encrypted ciphertext AAAC.AB.
Please recover the string before encryption from the encrypted ciphertext.
Input Format
The first line contains two integers , representing the length of the string before encryption and the size of the character set. The characters are numbered by integers , and the appended special character . is numbered by .
The second line contains integers, representing the encrypted string.
Output Format
Output a single line containing integers separated by spaces, representing the number of each character in the original string before encryption in order.
6 3
1 1 1 3 0 1 2
1 2 3 1 1 1
Hint
For the -th test point (), .
For test points , , and all characters in the string are distinct.
For test points , , and all characters in the string are distinct.
For test points , .
For test points , .
Translated by ChatGPT 5
京公网安备 11011102002149号