結果
問題 |
No.2411 Reverse Directions
|
ユーザー |
|
提出日時 | 2023-08-11 22:25:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,079 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 81,964 KB |
実行使用メモリ | 109,124 KB |
最終ジャッジ日時 | 2024-11-18 17:01:28 |
合計ジャッジ時間 | 6,793 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 WA * 2 RE * 18 |
ソースコード
import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 h, w, K, l, r = mi() s = [input() for _ in range(h)] dist = [[inf] * w for _ in range(h)] bef = [[None] * w for _ in range(h)] dist[0][0] = 0 bef[0][0] = (0, 0) q = deque() q.append((0, 0)) dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] dz = 'UDLR' while q: nowi, nowj = q.popleft() for to in range(4): toi = nowi + dx[to] toj = nowj + dy[to] if 0 <= toi < h and 0 <= toj < w and s[toi][toj] == '.' and dist[toi][toj] > dist[nowi][nowj] + 1: dist[toi][toj] = dist[nowi][nowj] + 1 bef[toi][toj] = (nowi, nowj) q.append((toi, toj)) if dist[h - 1][w - 1] > K - (r - l + 1) or dist[h - 1][w - 1] % 2 != K % 2: print('No') else: root = [(h - 1, w - 1)] nowi, nowj = h - 1, w - 1 while True: toi, toj = bef[nowi][nowj] if toi == nowi and toj == nowj: break root.append((toi, toj)) nowi = toi nowj = toj root.reverse() x = [] for i in range(len(root) - 1): if root[i + 1][0] - root[i][0] == 1: x.append('R') elif root[i + 1][0] - root[i][0] == -1: x.append('L') elif root[i + 1][1] - root[i][1] == 1: x.append('D') else: x.append('U') x = deque(x) ans = [] nowi = 0 nowj = 0 while len(ans) < K: if l - 1 <= len(ans) < r: for k in range(4): toi = nowi + dx[k] toj = nowj + dy[k] if 0 <= toi < h and 0 <= toj < w and s[toi][toj] == '.': ans.append(dz[k]) ans.append(dz[k^1]) break else: ans.append(x.popleft()) nowi += dx[dz.index(ans[-1])] nowj += dy[dz.index(ans[-1])] print('Yes') print(''.join(ans))