結果

問題 No.2411 Reverse Directions
ユーザー ShirotsumeShirotsume
提出日時 2023-08-11 22:27:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,088 bytes
コンパイル時間 445 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 122,484 KB
最終ジャッジ日時 2024-04-29 13:29:26
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,296 KB
testcase_01 AC 43 ms
55,424 KB
testcase_02 AC 45 ms
55,424 KB
testcase_03 AC 49 ms
55,680 KB
testcase_04 WA -
testcase_05 AC 44 ms
56,064 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 233 ms
117,088 KB
testcase_11 WA -
testcase_12 AC 146 ms
98,728 KB
testcase_13 WA -
testcase_14 AC 100 ms
91,008 KB
testcase_15 WA -
testcase_16 AC 61 ms
68,480 KB
testcase_17 AC 99 ms
85,760 KB
testcase_18 WA -
testcase_19 AC 44 ms
56,192 KB
testcase_20 AC 86 ms
79,872 KB
testcase_21 AC 84 ms
79,616 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 111 ms
82,636 KB
testcase_25 AC 62 ms
70,400 KB
testcase_26 AC 44 ms
55,680 KB
testcase_27 AC 68 ms
71,680 KB
testcase_28 WA -
testcase_29 AC 181 ms
122,484 KB
testcase_30 WA -
testcase_31 AC 89 ms
80,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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('D')
        elif root[i + 1][0] - root[i][0] == -1:
            x.append('U')
        elif root[i + 1][1] - root[i][1] == 1:
            x.append('R')
        else:
            x.append('L')
    
    x = deque(x)
    ans = []
    nowi = 0
    nowj = 0

    while len(ans) < K:
        if l - 1 <= len(ans) < r or not x:
            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))
0