시간 제한메모리 제한제출정답맞힌 사람정답 비율
20 초 (추가 시간 없음) 1024 MB0000.000%

문제

Two companies, Apricot Rules LLC and Banana Rocks Inc., are sharing the same datacenter. The datacenter is a matrix of R rows and C 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 x and y are considered connected if x is connected to a cell that is, directly or indirectly, connected to y. 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 (i, j) to represent the cell at row i and column j. At most one narrow hallway can be built through any given vertex, which means either (i, j) and (i + 1, j + 1) can be connected, or (i + 1, j) and (i, j + 1) 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 A or B depending on which company it is assigned to, find a way to add connections through diagonal adjacencies such that all As are connected and all Bs are connected.

입력

The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with one line containing two integers R and C, the number of rows and columns of the matrix representing the datacenter. Then, there are R more lines containing C characters each. The j-th character on the i-th of these lines Mi,j is either A or B, indicating which company owns the cell at (i, j).

출력

For each test case, first output one line containing Case #x: y, where x is the test case number (starting from 1) and y is IMPOSSIBLE if there is no way to assign the diagonal connections such that the A cells are connected and the B cells are connected, or POSSIBLE otherwise. Then, if you output POSSIBLE, output R - 1 more lines of C - 1 characters each. These characters must correspond to a valid arrangement as described in the statement above. The j-th character of the i-th of those lines must be \ if cells (i, j) and (i + 1, j + 1) are to be connected, / if cells (i + 1, j) and (i, j + 1) are to be connected, or . if neither pair is to be connected.

제한

  • 1 ≤ T ≤ 100.
  • 2 ≤ C ≤ 100.
  • Mi,j = uppercase A or uppercase B, for all i and j.
  • Mi,j = uppercase A for at least one pair of i and j.
  • Mi,j = uppercase B for at least one pair of i and j.

Test Set 1 (10점)

  • 2 ≤ R ≤ 4.

Test Set 2 (13점)

  • 2 ≤ R ≤ 100.

예제 입력 1

3
2 2
AB
BA
2 3
AAB
ABB
3 4
BBAA
BABA
BBAA

예제 출력 1

Case #1: IMPOSSIBLE
Case #2: POSSIBLE
..
Case #3: POSSIBLE
//\
.//

힌트

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.

출처

Contest > Google > Code Jam > Google Code Jam 2019 > Round 3 C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.