#P4663. [BalticOI 2008] 魔法石 (Day1)
[BalticOI 2008] 魔法石 (Day1)
Description
The famous stone can only be found in Wonderland. Such a stone is a granite slab engraved with an inscription consisting only of the letters X and I. Each slab contains letters. On each slab, there are at most positions where X and I are adjacent.
The top and bottom of a slab are not fixed, so the stone can be rotated and become upside down. For example, the following two pictures describe the same stone.

【Two ways to view the same stone. This stone is of type , and also (of course it can also be , ).】
Now, in Wonderland, no two magic stones are the same, meaning that no two stones have the same inscription (note that a rotation is considered the same).
If a stone’s inscription can be read in two different ways (by rotating it ), then the standard way to read the inscription is defined as the lexicographically smaller of the two readings.
If a stone’s inscription is symmetric, meaning that rotating it does not change the inscription, then the standard way to read the inscription is defined as this unique reading.
For example, there are six kinds of magic stones. Their standard readings, written in lexicographical order, are: III, IIX, IXI, IXX, XIX, and XXX.
Alice is an expert in studying magic stones in Wonderland. She wants to create a dictionary of standard readings of magic stones (for some given and ). For a given , what inscription should be at position in this dictionary?
Task
Write a program that:
- reads integers , , from standard input;
- determines the -th standard reading (in lexicographical order) among magic stones;
- outputs the result to standard output.
Input Format
The standard input contains only one line with three integers , separated by a single space.
Output Format
The standard output contains only one line, which should be the -th standard reading (in lexicographical order) of magic stones.
If the number of magic stones is smaller than , output one line with the phrase NO SUCH STONE.
3 2 5
XIX
3 2 7
NO SUCH STONE
Hint
Constraints and Hints
For all data, , .
Notes
Note: We say the inscription of is lexicographically smaller than that of (assuming they have the same length) if and only if at the first position where they differ, contains I and contains X.
Translated by ChatGPT 5
京公网安备 11011102002149号