結果
問題 | No.2411 Reverse Directions |
ユーザー | miya145592 |
提出日時 | 2023-08-11 23:19:59 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,570 bytes |
コンパイル時間 | 301 ms |
コンパイル使用メモリ | 82,456 KB |
実行使用メモリ | 112,356 KB |
最終ジャッジ日時 | 2024-11-18 18:46:15 |
合計ジャッジ時間 | 7,218 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 43 ms
55,256 KB |
testcase_02 | AC | 42 ms
54,436 KB |
testcase_03 | AC | 43 ms
54,376 KB |
testcase_04 | RE | - |
testcase_05 | AC | 44 ms
55,040 KB |
testcase_06 | AC | 41 ms
55,116 KB |
testcase_07 | AC | 119 ms
85,208 KB |
testcase_08 | AC | 42 ms
54,912 KB |
testcase_09 | AC | 44 ms
55,128 KB |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 44 ms
55,868 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | AC | 42 ms
55,512 KB |
testcase_20 | RE | - |
testcase_21 | AC | 46 ms
56,268 KB |
testcase_22 | RE | - |
testcase_23 | AC | 46 ms
56,992 KB |
testcase_24 | RE | - |
testcase_25 | AC | 45 ms
55,408 KB |
testcase_26 | RE | - |
testcase_27 | AC | 44 ms
56,476 KB |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | AC | 45 ms
57,704 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 v = dir_rev[now - pre_s[ii][jj]] 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 v = dir_rev2[now - pre_t[ii][jj]] order.append(v) now = pre_t[ii][jj] print("Yes") print("".join(order)) exit() print("No")