#P13121. [GCJ 2019 #3] Datacenter Duplex
[GCJ 2019 #3] Datacenter Duplex
题目描述
Two companies, Apricot Rules LLC and Banana Rocks Inc., are sharing the same datacenter. The datacenter is a matrix of rows and columns, with each cell containing a single server tower. Each tower contains intellectual property belonging to exactly one of the two companies.
At first, they built walls on the edges between cells assigned to different companies. This allowed orthogonally adjacent cells belonging to the same company to remain connected. Also, two cells and are considered connected if is connected to a cell that is, directly or indirectly, connected to . With this definition, it was possible that two cells assigned to the same company were not connected, which was unacceptable.
Both companies agreed to build narrow hallways running through cell corners that allow two diagonally adjacent cells to be connected directly. Let us write to represent the cell at row and column . At most one narrow hallway can be built through any given vertex, which means either and can be connected, or and can be connected, or neither pair, but not both. Of course, only hallways between cells assigned to the same company can be built.
Given a matrix where each cell is labeled or depending on which company it is assigned to, find a way to add connections through diagonal adjacencies such that all s are connected and all s are connected.
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each test case begins with one line containing two integers and , the number of rows and columns of the matrix representing the datacenter. Then, there are more lines containing characters each. The -th character on the -th of these lines $\mathbf{M}
输出格式
For each test case, first output one line containing Case #x: y
, where is the test case number (starting from 1) and is IMPOSSIBLE
if there is no way to assign the diagonal connections such that the cells are connected and the cells are connected, or POSSIBLE
otherwise. Then, if you output POSSIBLE
, output more lines of characters each. These characters must correspond to a valid arrangement as described in the statement above. The -th character of the -th of those lines must be if cells and are to be connected, / if cells and are to be connected, or . if neither pair is to be connected.
3
2 2
AB
BA
2 3
AAB
ABB
3 4
BBAA
BABA
BBAA
Case #1: IMPOSSIBLE
Case #2: POSSIBLE
..
Case #3: POSSIBLE
//\
.//
提示
Sample Explanation
In Sample Case #1, the pair of A cells and the pair of B cells need to be connected, but since both connections would have to cross the same vertex, at most one of the connections can exist.
In Sample Case #2, the cells are already connected in the required way in the input, so no additional connections are necessary. Note that you can add unnecessary valid connections, so another valid answer would be //
, but \.
would be wrong.
In Sample Case #3, there are also multiple solutions, one of which is displayed.
Limits
- .
- .
- = uppercase A or uppercase B, for all and .
- = uppercase A for at least one pair of and .
- = uppercase B for at least one pair of and .
Test set 1 (10 Pts, Visible)
- .
Test set 2 (13 Pts, Hidden)
- .