結果
問題 | No.2411 Reverse Directions |
ユーザー | sotanishy |
提出日時 | 2023-08-11 22:54:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,054 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 122,124 KB |
最終ジャッジ日時 | 2024-11-18 18:04:33 |
合計ジャッジ時間 | 5,669 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
55,172 KB |
testcase_01 | AC | 39 ms
53,352 KB |
testcase_02 | AC | 42 ms
54,780 KB |
testcase_03 | AC | 42 ms
54,784 KB |
testcase_04 | AC | 86 ms
112,756 KB |
testcase_05 | AC | 40 ms
53,908 KB |
testcase_06 | AC | 43 ms
54,436 KB |
testcase_07 | AC | 89 ms
84,040 KB |
testcase_08 | AC | 39 ms
53,360 KB |
testcase_09 | AC | 38 ms
53,296 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 39 ms
53,092 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 86 ms
77,076 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 39 ms
53,744 KB |
testcase_20 | WA | - |
testcase_21 | AC | 40 ms
53,852 KB |
testcase_22 | WA | - |
testcase_23 | AC | 40 ms
53,548 KB |
testcase_24 | WA | - |
testcase_25 | AC | 38 ms
53,732 KB |
testcase_26 | AC | 63 ms
70,984 KB |
testcase_27 | AC | 37 ms
53,804 KB |
testcase_28 | WA | - |
testcase_29 | AC | 171 ms
115,756 KB |
testcase_30 | WA | - |
testcase_31 | AC | 40 ms
54,612 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 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: # i if 0 < i < H-1 and S[i-1][j] == '.' and S[i+1][j] == '.': if distt[i][j] <= K-R: out(i, j, [0, 2]) exit() # j if 0 < j < W-1 and S[i][j-1] == '.' and S[i][j+1] == '.': if distt[i][j] <= K-R: out(i, j, [1, 3]) exit() print("No")