#5060. [GCJ Farewell Round #3] Game Sort: Part 2

    ID: 5060 传统题 40000ms 2048MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P12960贪心2023Special Judge构造Google Code Jam

[GCJ Farewell Round #3] Game Sort: Part 2

[GCJ Farewell Round #3] Game Sort: Part 2

题目描述

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 S\mathbf{S} and an integer P\mathbf{P} being chosen by an impartial judge. Then, Amir has to split S\mathbf{S} into exactly P\mathbf{P} contiguous non-empty parts (substrings). For example, if S=CODEJAM\mathbf{S} = \text{CODEJAM} was the chosen string and P=3\mathbf{P} = 3, Amir could split it up as [COD,EJA,M][\text{COD}, \text{EJA}, \text{M}] or as [CO,D,EJAM][\text{CO}, \text{D}, \text{EJAM}], but not as [COD,EJAM][\text{COD}, \text{EJAM}], [COD,JA,M][\text{COD}, \text{JA}, \text{M}], [EJA,COD,M][\text{EJA}, \text{COD}, \text{M}], nor as [CODE,EJA,M][\text{CODE}, \text{EJA}, \text{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 \ldots t_p$ where $t_i$ is the $i$-th part of the winning partition you found for Amir. If there are multiple solutions, you may output any one of them.
3
3 CODEJAM
2 ABABABABAAAA
3 AABBCDEEFGHIJJKLMNOPQRRSTUVWXYZZ
Case #1: POSSIBLE
C O DEJAM
Case #2: POSSIBLE
ABABABABA AAA
Case #3: IMPOSSIBLE

提示

**Sample Explanation**

In Sample Case #1, there is no way for Badari to rearrange DEJAM\text{DEJAM} to be lexicographically after O\text{O}, so Amir guaranteed a win.

In Sample Case #2, AAA\text{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.

Limits

1≤T≤1001 \leq \mathbf{T} \leq 100.

Each character of S\mathbf{S} is an English uppercase letter A through Z.

Test Set 1 (8 Pts, Visible Verdict)

  • 2≤P≤32 \leq \mathbf{P} \leq 3.
  • $\mathbf{P} \leq \text{the length of } \mathbf{S} \leq 100$.

Test Set 2 (20 Pts, Hidden Verdict)

  • 2≤P≤1002 \leq \mathbf{P} \leq 100.
  • $\mathbf{P} \leq \text{the length of } \mathbf{S} \leq 10^5$. 标签: P12960|贪心|2023|Special Judge|构造|Google Code Jam

来源

P12960|[GCJ Farewell Round #3] Game Sort: Part 2