結果
問題 | No.2411 Reverse Directions |
ユーザー | sotanishy |
提出日時 | 2023-08-11 23:03:58 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,235 bytes |
コンパイル時間 | 329 ms |
コンパイル使用メモリ | 82,088 KB |
実行使用メモリ | 122,552 KB |
最終ジャッジ日時 | 2024-11-18 18:21:23 |
合計ジャッジ時間 | 4,738 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
55,096 KB |
testcase_01 | AC | 42 ms
54,192 KB |
testcase_02 | AC | 44 ms
55,272 KB |
testcase_03 | AC | 43 ms
55,460 KB |
testcase_04 | AC | 88 ms
113,508 KB |
testcase_05 | AC | 39 ms
54,116 KB |
testcase_06 | AC | 44 ms
55,236 KB |
testcase_07 | AC | 93 ms
83,720 KB |
testcase_08 | AC | 39 ms
54,004 KB |
testcase_09 | AC | 39 ms
53,168 KB |
testcase_10 | AC | 175 ms
122,552 KB |
testcase_11 | AC | 43 ms
55,844 KB |
testcase_12 | WA | - |
testcase_13 | AC | 40 ms
54,216 KB |
testcase_14 | AC | 118 ms
85,028 KB |
testcase_15 | AC | 89 ms
83,900 KB |
testcase_16 | AC | 73 ms
74,608 KB |
testcase_17 | AC | 119 ms
85,068 KB |
testcase_18 | AC | 100 ms
91,172 KB |
testcase_19 | AC | 39 ms
53,032 KB |
testcase_20 | WA | - |
testcase_21 | AC | 41 ms
54,784 KB |
testcase_22 | AC | 161 ms
92,228 KB |
testcase_23 | AC | 41 ms
54,180 KB |
testcase_24 | AC | 160 ms
85,472 KB |
testcase_25 | AC | 40 ms
52,964 KB |
testcase_26 | AC | 65 ms
71,196 KB |
testcase_27 | AC | 40 ms
54,512 KB |
testcase_28 | AC | 153 ms
109,304 KB |
testcase_29 | AC | 185 ms
116,732 KB |
testcase_30 | AC | 161 ms
110,880 KB |
testcase_31 | AC | 41 ms
53,812 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 = i+di, j+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")