Cipher
Time limit1sMemory limit128 MB
Given total character volume, word count, and rank, reconstruct the I-th message in lexicographic order or report corruption.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, String
- Solved
- No attempts yet
Problem
A spy exchanges messages with a very efficient cipher. However long a message is, three numbers carry it.
The Department of National Security worked out the rules.
- A message uses only lowercase English letters and the space character. Every character has an integer called its character volume. A space has volume ,
ahas volume ,bhas volume , and so on up toz, which has volume . The volume of a message is the sum of the volumes of the characters in it. - A message consists of words. A word is a consecutive run of lowercase letters, a message has no leading or trailing space, and neighbouring words are separated by exactly one space.
- For a given and , let be the lexicographically sorted list of every message whose volume is and which consists of exactly words. A one-based index can point at one message in .
So when the spy wants to send a message , he computes the volume and the word count of , finds the index of in the matching list , and sends only the three numbers , , and .
You are given , , and . Decrypt the spy's message, or report that no such message exists.
In the lexicographic comparison the space character comes before every lowercase letter.
Input
The first line contains the number of test cases . ()
Each of the next lines contains three integers separated by spaces: the volume of the message , the number of words , and the index of the message . (, , )
Output
For each test case, print one line that starts with Case #x: and then the decrypted message. Here is the test case number starting from . If no message matches the given , , and , print Corrupted! in place of the message.
Hint
Sorting every message of volume that has words gives five of them: a aa, a c, aa a, b b, c a. Index therefore points at aa a.
Volume with word allows only a. The list holds a single message, so a request for index means something went wrong.