結果
問題 | No.2411 Reverse Directions |
ユーザー | miya145592 |
提出日時 | 2023-08-11 23:21:32 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,622 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,324 KB |
実行使用メモリ | 111,960 KB |
最終ジャッジ日時 | 2024-11-18 18:47:49 |
合計ジャッジ時間 | 7,207 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
55,224 KB |
testcase_01 | AC | 44 ms
55,728 KB |
testcase_02 | AC | 44 ms
55,620 KB |
testcase_03 | AC | 47 ms
54,560 KB |
testcase_04 | AC | 71 ms
80,120 KB |
testcase_05 | AC | 44 ms
55,208 KB |
testcase_06 | AC | 44 ms
55,548 KB |
testcase_07 | AC | 126 ms
85,268 KB |
testcase_08 | AC | 43 ms
55,268 KB |
testcase_09 | AC | 45 ms
54,496 KB |
testcase_10 | RE | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 45 ms
55,360 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | RE | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 44 ms
54,964 KB |
testcase_20 | WA | - |
testcase_21 | AC | 48 ms
57,196 KB |
testcase_22 | WA | - |
testcase_23 | AC | 48 ms
57,676 KB |
testcase_24 | WA | - |
testcase_25 | AC | 47 ms
56,760 KB |
testcase_26 | RE | - |
testcase_27 | AC | 46 ms
56,044 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 48 ms
56,572 KB |
ソースコード
from collections import deque H, W, K, L, R = map(int, input().split()) S = [input() for _ in range(H)] if (R-L+1)%2==1: print("No") exit() if ((H-1)+(W-1))%2!=K%2: print("No") exit() ok = set() for i in range(H): for j in range(W): ud = 0 if 0<i<H-1 and S[i-1][j]==S[i][j]==S[i+1][j]==".": ud = 1 lr = 0 if 0<j<W-1 and S[i][j-1]==S[i][j]==S[i][j+1]==".": lr = 1 if ud or lr: ok.add((i, j, ud, lr)) dir = [(1, 0), (0, 1), (-1, 0), (0, -1)] INF = 10**3 deq = deque() dist_s = [[INF for _ in range(W)] for _ in range(H)] pre_s = [[(-1, -1) for _ in range(W)] for _ in range(H)] deq.append((0, 0)) dist_s[0][0] = 0 while deq: i, j = deq.popleft() for di, dj in dir: ni = i+di nj = j+dj if 0<=ni<H and 0<=nj<W and S[ni][nj]==".": if dist_s[ni][nj] > dist_s[i][j]+1: dist_s[ni][nj] = dist_s[i][j]+1 pre_s[ni][nj] = (i, j) deq.append((ni, nj)) if dist_s[H-1][W-1]>K: print("No") exit() deq = deque() dist_t = [[INF for _ in range(W)] for _ in range(H)] pre_t = [[(-1, -1) for _ in range(W)] for _ in range(H)] deq.append((H-1, W-1)) dist_t[H-1][W-1] = 0 while deq: i, j = deq.popleft() for di, dj in dir: ni = i+di nj = j+dj if 0<=ni<H and 0<=nj<W and S[ni][nj]==".": if dist_t[ni][nj] > dist_t[i][j]+1: dist_t[ni][nj] = dist_t[i][j]+1 pre_t[ni][nj] = (i, j) deq.append((ni, nj)) dir_rev = dict() dir_rev[(1, 0)] = "D" dir_rev[(0, 1)] = "R" dir_rev[(-1, 0)] = "U" dir_rev[(0, -1)] = "L" dir_rev2 =dict() dir_rev2[(1, 0)] = "U" dir_rev2[(0, 1)] = "L" dir_rev2[(-1, 0)] = "D" dir_rev2[(0, -1)] = "R" for i, j, ud, lr in ok: d = dist_s[i][j] if L<=d: continue if (L-1)%2!=d%2: continue d = dist_t[i][j] if (K-R)<d: continue if (K-R)%2!=d%2: continue order = [] now = (i, j) while now != (0, 0): ii, jj = now pi, pj = pre_s[ii][jj] v = dir_rev[(ii-pi, jj-pj)] order.append(v) now = pre_s[ii][jj] order.reverse() if ud: for _ in range(0, R-L+1, 2): order.append("UD") else: for _ in range(0, R-L+1, 2): order.append("LR") now = (i, j) while now != (H-1, W-1): ii, jj = now pi, pj = pre_t[ii][jj] v = dir_rev2[(ii-pi, jj-pj)] order.append(v) now = pre_t[ii][jj] print("Yes") print("".join(order)) exit() print("No")