P28811 [洛谷] [BalticOI 2008] Magic Stones
提高+
题目描述

Problem Description

The renowned stone $\text{Xi-n-k}$ can only be found in Wonderland, and it is a granite slab inscribed with only the letters "X" and "I". Each slab contains $n$ letters, and there are no more than $k$ adjacent positions with "X" and "I" next to each other on each slab.

The top and bottom of the slab are not fixed, so the stone can be rotated to an inverted state. For example, the following two images depict the same stone.

0

(Two ways to view the same stone. This stone is of type $\text{Xi-8-3}$, and also $\text{Xi-8-4}$ (or $\text{Xi-8-k}$, $k \ge 3$).)

Currently, no two magic stones in Wonderland are the same, meaning no two stones have identical inscriptions (note that a $180^\circ$ rotation is allowed).

If a stone's inscription can be read in two different ways (by rotating $180^\circ$), the standard reading method for this stone is defined as the one with the smaller lexicographical order.

If a stone's inscription is symmetrical, meaning a $180^\circ$ rotation does not change the inscription, the standard reading method for this stone is defined as this unique way.

For example, there are six types of $\text{Xi-3-2}$ magic stones, and their standard reading methods written in lexicographical order are: "III", "IIX", "IXI", "IXX", "XIX", and "XXX".

Alice is an expert in studying the magic stones of Wonderland. She wants to create a dictionary of standard reading methods for $\text{Xi-n-k}$ magic stones (for some specific $n$ and $k$). Given $i$, what should be the inscription at the $i$-th position in the dictionary?

Task

Write a program that can:

  • Read the numbers $n$, $k$, and $i$ from standard input
  • Determine the $i$-th standard reading method (in lexicographical order) for $\text{Xi-n-k}$ magic stones
  • Output the result to standard output

Input Format

Standard input consists of a single line containing three numbers $n$, $k$, and $i$, separated by a space.

Output Format

Standard output should consist of a single line containing the $i$-th standard reading method (in lexicographical order) for $\text{Xi-n-k}$ magic stones.

If the number of $\text{Xi-n-k}$ magic stones is less than $i$, output a single line with the phrase "NO SUCH STONE".

Sample Input and Output

Sample Input #1

3 2 5

Sample Output #1

XIX

Sample Input #2

3 2 7

Sample Output #2

NO SUCH STONE

Notes/Hints

Data Range and Hints

For all data, $0 \le k < n \le 60, 0 < i < 10^{18}$.

Note: We say that inscription A is lexicographically smaller than inscription B (assuming A and B have the same length) if and only if A contains "I" and B contains "X" at the first position where they differ.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 5
样例输出
XIX