Logo
(追記) (追記ここまで)

31171번 - Jungle Trail 스페셜 저지다국어

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

문제

In the mobile game "Jungle Trail", you are given a rectangular $n \times m$ board divided into $n \cdot m$ squares. Each square is either empty, blocked (impassable) or contains a den of snakes, either poisonous or benign (not poisonous). If a square contains a den of snakes, then either all the snakes on a given field are poisonous, or all are benign.

The game allows you to tap any column or any row of the board. If you tap a column, all poisonous snakes in this column are turned to benign, and vice versa. Similarly, if you tap any row, all snakes in the row change their state. You can tap each row/column only once. If a den is in a tapped row as well as in a tapped column, its state returns to the original one.

After performing all those operations, you must find a trail through the jungle: a path which starts at the top left corner, in every move goes either one square down or one to the right, ends at the bottom right corner and never passes through a den of poisonous snakes or a blocked field.

입력

The first line of input contains the number of test cases $z$ (1ドル \le z \le 500$). The descriptions of the test cases follow.

The first line contains two integers $n$ and $m$ (2ドル \le n, m \le 2,000円$).

Each of the following $n$ lines contains $m$ characters ., #, O (capital o) and @ (at sign), meaning an empty square, blocked square, den of benign snakes and den of poisonous snakes, respectively. You may assume that the top left corner and the bottom right corner are not blocked.

Neither the sum of $n$ values over all test cases nor the sum of all $m$ values exceed 15ドル,000円$.

출력

For every test case output the solution in the following format:

The first line should contain TAK if a jungle trail is possible or NIE if it isn't.

If the answer is TAK, in the next three lines output:

  • A sequence of $n$ characters $T$ or $N,ドル the $i$-th character being $T$ if the $i$-th row should be tapped, $N$ if not;
  • A sequence of $m$ characters $T$ or $N,ドル determining in the same way whether the columns should be tapped;
  • A sequence of $n + m - 2$ characters $P$ or $D$ denoting the trail: $P$ means a move right, $D$ means a move down.

제한

예제 입력 1

1
4 5
..#..
@@O@@
##@#O
..@.@

예제 출력 1

TAK
NTNN
NNTNT
DPPDDPP

노트

After tapping the rows and columns described on the output, the board is in the following state:

..#..
OOOO@
##O#@
..O.O

Now the given path goes only through . and O squares.

출처

Contest > Open Cup > 2021/2022 Season > Stage 8: Grand Prix of Poland J번

ICPC > Regionals > Europe > Central European Regional Contest > Poland Collegiate Programming Contest > AMPPZ 2021 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /