| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 40 초 (추가 시간 없음) | 1024 MB | 18 | 3 | 3 | 25.000% |
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 $\mathbf{S}$ and an integer $\mathbf{P}$ being chosen by an impartial judge. Then, Amir has to split $\mathbf{S}$ into exactly $\mathbf{P}$ contiguous non-empty parts (substrings). For example, if $\mathbf{S} = \vphantom{}$CODEJAM was the chosen string and $\mathbf{P} = 3,ドル Amir could split it up as [COD, EJA, M] or as [CO, D, EJAM], but not as [COD, EJAM], [COD, JA, M], [EJA, COD, M], nor as [CODE, EJA, M].
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 initial string and number of parts, can you help Amir win the game by choosing his parts in a way Badari cannot win herself? If not, say that it is not possible.
The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ lines follow, each describing a single test case containing an integer $\mathbf{P}$ and a string $\mathbf{S},ドル the number of parts and string to be partitioned, respectively.
For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is either POSSIBLE if Amir can win the game, or IMPOSSIBLE if he cannot. If he can win the game, output a second line containing $t_1,円 t_2,円 \dots,円 t_{\mathbf{P}}$ where $t_i$ is a the $i$-th part of the winning partition you found for Amir. If there are multiple solutions, you may output any one of them.
A through Z.3 3 CODEJAM 2 ABABABABAAAA 3 AABBCDEEFGHIJJKLMNOPQRRSTUVWXYZZ
Case #1: POSSIBLE C O DEJAM Case #2: POSSIBLE ABABABABA AAA Case #3: IMPOSSIBLE
In Sample Case #1, there is no way for Badari to rearrange DEJAM to be lexicographically after O, so Amir guaranteed a win.
In Sample Case #2, AAA is guaranteed to be earlier than any rearrangement of a string containing more than 3ドル$ letters, so Amir also wins.
In Sample Case #3, all possible partitions result in a list of parts that is already sorted in lexicographical order, so Amir cannot possibly win.
Contest > Google > Code Jam > Google Code Jam Farewell Round > Round C E번