結果
問題 | No.2411 Reverse Directions |
ユーザー | sotanishy |
提出日時 | 2023-08-11 23:05:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 198 ms / 2,000 ms |
コード長 | 2,240 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 121,984 KB |
最終ジャッジ日時 | 2024-04-29 14:16:10 |
合計ジャッジ時間 | 5,111 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
54,016 KB |
testcase_01 | AC | 41 ms
52,352 KB |
testcase_02 | AC | 45 ms
54,016 KB |
testcase_03 | AC | 46 ms
54,016 KB |
testcase_04 | AC | 104 ms
112,896 KB |
testcase_05 | AC | 42 ms
52,480 KB |
testcase_06 | AC | 45 ms
54,016 KB |
testcase_07 | AC | 102 ms
83,456 KB |
testcase_08 | AC | 41 ms
52,096 KB |
testcase_09 | AC | 41 ms
51,968 KB |
testcase_10 | AC | 187 ms
121,984 KB |
testcase_11 | AC | 47 ms
53,888 KB |
testcase_12 | AC | 185 ms
94,104 KB |
testcase_13 | AC | 42 ms
52,608 KB |
testcase_14 | AC | 126 ms
84,992 KB |
testcase_15 | AC | 97 ms
83,968 KB |
testcase_16 | AC | 81 ms
74,368 KB |
testcase_17 | AC | 129 ms
84,992 KB |
testcase_18 | AC | 110 ms
90,848 KB |
testcase_19 | AC | 40 ms
52,352 KB |
testcase_20 | AC | 118 ms
79,488 KB |
testcase_21 | AC | 41 ms
52,864 KB |
testcase_22 | AC | 165 ms
92,160 KB |
testcase_23 | AC | 42 ms
53,504 KB |
testcase_24 | AC | 167 ms
84,992 KB |
testcase_25 | AC | 41 ms
52,224 KB |
testcase_26 | AC | 74 ms
70,656 KB |
testcase_27 | AC | 41 ms
52,480 KB |
testcase_28 | AC | 160 ms
108,800 KB |
testcase_29 | AC | 198 ms
116,352 KB |
testcase_30 | AC | 170 ms
110,592 KB |
testcase_31 | AC | 43 ms
53,504 KB |
ソースコード
import sys input = sys.stdin.readline move = [(1, 0), (0, 1), (-1, 0), (0, -1)] dirs = "DRUL" def bfs(si, sj): from collections import deque INF = 10**18 dist = [[INF] * W for _ in range(H)] prv = [[-1] * W for _ in range(H)] dist[si][sj] = 0 que = deque([(si, sj)]) while que: i, j = que.popleft() for k, (di, dj) in enumerate(move): ni, nj = i+di, j+dj if 0 <= ni < H and 0 <= nj < W and dist[ni][nj] == INF and S[ni][nj] == '.': dist[ni][nj] = dist[i][j] + 1 prv[ni][nj] = k que.append((ni, nj)) return dist, prv def out(si, sj, d): print("Yes") res = [] i, j = si, sj while True: p = prvs[i][j] if p == -1: break res.append(p) di, dj = move[p ^ 2] i += di j += dj res = res[::-1] for k, (di, dj) in enumerate(move): ni, nj = si+di, sj+dj if 0 <= ni < H and 0 <= nj < W and S[ni][nj] == '.': for l in range(L-1-len(res)): res.append(k ^ ((l % 2)*2)) break for k in range(R-L+1): res.append(d[k % 2]) i, j = si, sj while True: p = prvt[i][j] if p == -1: break res.append(p ^ 2) di, dj = move[p ^ 2] i += di j += dj if S[H-2][W-1] == '.': for k in range(K-len(res)): res.append([2, 0][k % 2]) else: for k in range(K-len(res)): res.append([3, 1][k % 2]) print("".join(map(lambda k: dirs[k], res))) H, W, K, L, R = map(int, input().split()) S = [input().rstrip() for _ in range(H)] if (H+W) % 2 != K % 2 or (R - L + 1) % 2 != 0: print("No") exit() dists, prvs = bfs(0, 0) distt, prvt = bfs(H-1, W-1) for i in range(H): for j in range(W): if (dists[i][j] - (L - 1)) % 2 == 0 and dists[i][j] <= L-1 and distt[i][j] <= K-R: # i if 0 < i < H-1 and S[i-1][j] == '.' and S[i+1][j] == '.': out(i, j, [0, 2]) exit() # j if 0 < j < W-1 and S[i][j-1] == '.' and S[i][j+1] == '.': out(i, j, [1, 3]) exit() print("No")