結果
| 問題 |
No.2411 Reverse Directions
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2023-08-12 03:09:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,873 bytes |
| コンパイル時間 | 195 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 104,448 KB |
| 最終ジャッジ日時 | 2024-11-18 23:30:09 |
| 合計ジャッジ時間 | 7,070 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 18 |
ソースコード
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))
titia