結果
問題 | No.2411 Reverse Directions |
ユーザー | detteiuu |
提出日時 | 2024-12-22 06:26:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 199 ms / 2,000 ms |
コード長 | 2,236 bytes |
コンパイル時間 | 433 ms |
コンパイル使用メモリ | 82,164 KB |
実行使用メモリ | 132,864 KB |
最終ジャッジ日時 | 2024-12-22 06:26:24 |
合計ジャッジ時間 | 5,940 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
54,144 KB |
testcase_01 | AC | 43 ms
54,400 KB |
testcase_02 | AC | 37 ms
54,144 KB |
testcase_03 | AC | 38 ms
54,400 KB |
testcase_04 | AC | 86 ms
110,976 KB |
testcase_05 | AC | 39 ms
53,888 KB |
testcase_06 | AC | 43 ms
54,400 KB |
testcase_07 | AC | 91 ms
87,168 KB |
testcase_08 | AC | 42 ms
53,888 KB |
testcase_09 | AC | 40 ms
54,400 KB |
testcase_10 | AC | 181 ms
122,352 KB |
testcase_11 | AC | 43 ms
54,528 KB |
testcase_12 | AC | 183 ms
109,184 KB |
testcase_13 | AC | 43 ms
57,600 KB |
testcase_14 | AC | 125 ms
94,768 KB |
testcase_15 | AC | 75 ms
81,536 KB |
testcase_16 | AC | 66 ms
72,448 KB |
testcase_17 | AC | 107 ms
85,504 KB |
testcase_18 | AC | 92 ms
94,592 KB |
testcase_19 | AC | 40 ms
54,144 KB |
testcase_20 | AC | 99 ms
79,872 KB |
testcase_21 | AC | 94 ms
80,644 KB |
testcase_22 | AC | 176 ms
99,012 KB |
testcase_23 | AC | 44 ms
60,288 KB |
testcase_24 | AC | 165 ms
90,112 KB |
testcase_25 | AC | 42 ms
56,064 KB |
testcase_26 | AC | 56 ms
69,120 KB |
testcase_27 | AC | 101 ms
78,336 KB |
testcase_28 | AC | 144 ms
120,448 KB |
testcase_29 | AC | 199 ms
132,864 KB |
testcase_30 | AC | 185 ms
121,600 KB |
testcase_31 | AC | 133 ms
84,100 KB |
ソースコード
from collections import deque H, W, K, L, R = map(int, input().split()) S = [list(input()) for _ in range(H)] if (R-L+1)%2 == 1: exit(print("No")) def bfs(sh, sw): visited = [[-1]*W for _ in range(H)] visited[sh][sw] = 0 que = deque() que.append((sh, sw)) while que: h, w = que.popleft() for dh, dw in direction: nh, nw = h+dh, w+dw if 0<=nh<H and 0<=nw<W and visited[nh][nw] == -1 and S[nh][nw] == ".": visited[nh][nw] = visited[h][w]+1 que.append((nh, nw)) return visited def root(h, w, gh, gw, dist, B): ans = [] while [h, w] != [gh, gw]: for i, (dh, dw) in enumerate(direction): nh, nw = h+dh, w+dw if 0<=nh<H and 0<=nw<W and dist[nh][nw] == dist[h][w]-1: ans.append(B[i]) h, w = nh, nw break return ans direction = [(-1,0),(0,1),(1,0),(0,-1)] distS = bfs(0, 0) distG = bfs(H-1, W-1) for i in range(H): for j in range(W): if distS[i][j] == -1 or distG[i][j] == -1: continue if distS[i][j]+distG[i][j] > K or (distS[i][j]+distG[i][j])%2 != K%2: continue if distS[i][j] >= L or distS[i][j]%2 == L%2: continue r = K-R if distG[i][j] > r or distG[i][j]%2 != r%2: continue if 1 <= j < W-1 and S[i][j-1] == S[i][j+1] == ".": start = root(i, j, 0, 0, distS, ["D", "L", "U", "R"])[::-1] mid = [] for _ in range((K-distS[i][j]-distG[i][j])//2): mid.append("L") mid.append("R") goal = root(i, j, H-1, W-1, distG, ["U", "R", "D", "L"]) print("Yes") print("".join(start+mid+goal)) exit() if 1 <= i < H-1 and S[i-1][j] == S[i+1][j] == ".": start = root(i, j, 0, 0, distS, ["D", "L", "U", "R"])[::-1] mid = [] for _ in range((K-distS[i][j]-distG[i][j])//2): mid.append("U") mid.append("D") goal = root(i, j, H-1, W-1, distG, ["U", "R", "D", "L"]) print("Yes") print("".join(start+mid+goal)) exit() print("No")