結果

問題 No.2411 Reverse Directions
ユーザー titiatitia
提出日時 2023-08-12 03:09:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,873 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 104,192 KB
最終ジャッジ日時 2024-04-29 17:44:59
合計ジャッジ時間 7,566 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,888 KB
testcase_01 AC 45 ms
53,888 KB
testcase_02 AC 46 ms
54,272 KB
testcase_03 AC 44 ms
54,016 KB
testcase_04 WA -
testcase_05 AC 44 ms
54,144 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 44 ms
54,016 KB
testcase_09 AC 45 ms
53,760 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 46 ms
53,760 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 74 ms
71,168 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 48 ms
53,888 KB
testcase_20 WA -
testcase_21 AC 99 ms
78,464 KB
testcase_22 WA -
testcase_23 AC 44 ms
53,760 KB
testcase_24 WA -
testcase_25 AC 44 ms
54,016 KB
testcase_26 AC 66 ms
68,608 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import deque

H,W,K,L,R=map(int,input().split())

if (R-L+1)%2!=0:
    print("No")
    exit()

MAP=[input().strip() for i in range(H)]

F=[[1<<30]*W for i in range(H)]
BACK=[[-1]*W for i in range(H)]

F[0][0]=0

Q=deque()
Q.append((0,0))

while Q:
    x,y=Q.popleft()

    for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if 0<=z<H and 0<=w<W and MAP[z][w]=="." and F[z][w]==1<<30:
            F[z][w]=F[x][y]+1
            Q.append((z,w))
            BACK[z][w]=(x,y)

F2=[[1<<30]*W for i in range(H)]
BACK2=[[-1]*W for i in range(H)]

F2[H-1][W-1]=0

Q=deque()
Q.append((H-1,W-1))

while Q:
    x,y=Q.popleft()

    for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if 0<=z<H and 0<=w<W and MAP[z][w]=="." and F2[z][w]==1<<30:
            F2[z][w]=F2[x][y]+1
            Q.append((z,w))
            BACK2[z][w]=(x,y)


gx=-1
gy=-1
for i in range(H):
    for j in range(W):
        if F[i][j]<=L-1 and F2[i][j]<=K-R:
            gx,gy=i,j

if gx==-1:
    print("No")
    exit()

ANS1=[]
ANS2=[]

x=gx
y=gy

while x!=0 or y!=0:
    z,w=BACK[x][y]

    if z==x+1:
        ANS1.append("U")
    elif z==x-1:
        ANS1.append("D")
    elif w==y+1:
        ANS1.append("L")
    else:
        ANS1.append("R")

    x,y=z,w

x=gx
y=gy

while x!=H-1 or y!=W-1:
    z,w=BACK2[x][y]

    if z==x+1:
        ANS2.append("D")
    elif z==x-1:
        ANS2.append("U")
    elif w==y+1:
        ANS2.append("R")
    else:
        ANS2.append("L")

    x,y=z,w

ANS1.reverse()

if gx+1<H and MAP[gx+1][gy]==".":
    ANS3=["D","U"]*((R-L+1)//2)


elif gx>=1 and MAP[gx-1][gy]==".":
    ANS3=["U","D"]*((R-L+1)//2)

elif gy+1<W and MAP[gx][gy+1]==".":
    ANS3=["R","L"]*((R-L+1)//2)

elif gy>=1 and MAP[gx][gy-1]==".":
    ANS3=["L","R"]*((R-L+1)//2)

ANS=ANS1+ANS3+ANS2

print("Yes")
print("".join(ANS))
        
    


0