結果

問題 No.2411 Reverse Directions
ユーザー sotanishysotanishy
提出日時 2023-08-11 23:03:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,235 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 121,984 KB
最終ジャッジ日時 2024-04-29 14:14:44
合計ジャッジ時間 4,166 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,400 KB
testcase_01 AC 36 ms
52,480 KB
testcase_02 AC 37 ms
54,144 KB
testcase_03 AC 40 ms
53,632 KB
testcase_04 AC 83 ms
113,024 KB
testcase_05 AC 35 ms
51,968 KB
testcase_06 AC 41 ms
54,400 KB
testcase_07 AC 85 ms
83,328 KB
testcase_08 AC 37 ms
52,736 KB
testcase_09 AC 37 ms
52,352 KB
testcase_10 AC 160 ms
121,984 KB
testcase_11 AC 41 ms
54,016 KB
testcase_12 WA -
testcase_13 AC 36 ms
52,864 KB
testcase_14 AC 107 ms
85,120 KB
testcase_15 AC 79 ms
83,840 KB
testcase_16 AC 66 ms
74,752 KB
testcase_17 AC 105 ms
84,608 KB
testcase_18 AC 88 ms
90,852 KB
testcase_19 AC 36 ms
52,352 KB
testcase_20 WA -
testcase_21 AC 36 ms
52,736 KB
testcase_22 AC 139 ms
92,032 KB
testcase_23 AC 35 ms
52,992 KB
testcase_24 AC 139 ms
85,120 KB
testcase_25 AC 36 ms
52,224 KB
testcase_26 AC 59 ms
70,400 KB
testcase_27 AC 36 ms
52,864 KB
testcase_28 AC 134 ms
109,056 KB
testcase_29 AC 162 ms
116,736 KB
testcase_30 AC 145 ms
110,720 KB
testcase_31 AC 37 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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")
0