#P12956. [GCJ Farewell Round #3] Game Sort: Part 1
[GCJ Farewell Round #3] Game Sort: Part 1
题目描述
Note: The main parts of the statements of the problems "Game Sort: Part 1" and "Game Sort: Part 2" are identical, except for the last paragraph. The problems can otherwise be solved independently.
Amir and Badari are playing a sorting game. The game starts with a string and an integer being chosen by an impartial judge. Then, Amir has to split into exactly contiguous non-empty parts (substrings). For example, if was the chosen string and , Amir could split it up as or as , but not as , , , nor as .
Then, Badari must rearrange the letters within each part to make the list of parts be sorted in non-decreasing lexicographical order. If she can, then she wins. Otherwise, Amir wins.
Given the partition Amir made, can you help Badari win the game, or say that it is not possible?
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines. The first line of a test case contains a single integer , the number of parts Amir made. The second line contains strings $\mathbf{S}_1, \mathbf{S}_2, \ldots, \mathbf{S}_\mathbf{P}$, representing the parts, in order.
输出格式
For each test case, output one line containing Case #x: y
, where is the test case number (starting from 1) and is either if Badari can win the game, or if she cannot. If she can win the game, output a second line containing where is a rearrangement of the letters of , and is lexicographically earlier than or equal to , for all . If there are multiple solutions, you may output any one of them.
3
3
CO DEJ AM
3
CODE JA M
2
ABABABAB AAA
Case #1: POSSIBLE
CO DEJ MA
Case #2: POSSIBLE
CODE JA M
Case #3: IMPOSSIBLE
提示
Sample Explanation
In Sample Case #1, Badari could also win in 5 other ways. Two of them are and .
In Sample Case #2, Badari can win simply by leaving all parts as Amir gave it to her, but other ways are also possible.
In Sample Case #3 Amir has guaranteed a win for himself leaving Badari no winning option.
Limits
.
Each character of is an English uppercase letter A through Z, for all .
Test Set 1 (4 Pts, Visible Verdict)
- .
- , for all .
Test Set 2 (9 Pts, Hidden Verdict)
- .
- , for all .