結果
問題 | No.2411 Reverse Directions |
ユーザー | miya145592 |
提出日時 | 2023-08-11 23:43:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,574 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 119,120 KB |
最終ジャッジ日時 | 2024-11-18 19:24:30 |
合計ジャッジ時間 | 6,512 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,272 KB |
testcase_01 | AC | 42 ms
53,888 KB |
testcase_02 | AC | 43 ms
54,528 KB |
testcase_03 | AC | 43 ms
54,656 KB |
testcase_04 | AC | 66 ms
79,744 KB |
testcase_05 | AC | 42 ms
54,016 KB |
testcase_06 | AC | 41 ms
54,656 KB |
testcase_07 | AC | 122 ms
85,248 KB |
testcase_08 | AC | 42 ms
54,144 KB |
testcase_09 | AC | 40 ms
54,144 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 43 ms
55,296 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 93 ms
78,128 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 42 ms
54,656 KB |
testcase_20 | WA | - |
testcase_21 | AC | 44 ms
55,680 KB |
testcase_22 | WA | - |
testcase_23 | AC | 48 ms
56,192 KB |
testcase_24 | WA | - |
testcase_25 | AC | 43 ms
54,912 KB |
testcase_26 | AC | 79 ms
77,440 KB |
testcase_27 | AC | 45 ms
55,040 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 45 ms
56,064 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**9 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" for i, j, ud, lr in ok: d = dist_s[i][j] if d==INF: continue if L<=d: continue if (L-1)%2!=d%2: continue d = dist_t[i][j] if d==INF: continue 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_rev[(pi-ii, pj-jj)] order.append(v) now = pre_t[ii][jj] print("Yes") print("".join(order)) exit() print("No")