結果
問題 | No.2411 Reverse Directions |
ユーザー | titia |
提出日時 | 2023-08-12 03:24:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,117 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 104,300 KB |
最終ジャッジ日時 | 2024-11-18 23:45:00 |
合計ジャッジ時間 | 6,905 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,656 KB |
testcase_01 | AC | 45 ms
54,272 KB |
testcase_02 | AC | 45 ms
54,528 KB |
testcase_03 | AC | 43 ms
54,400 KB |
testcase_04 | AC | 66 ms
71,936 KB |
testcase_05 | AC | 43 ms
54,656 KB |
testcase_06 | AC | 43 ms
54,400 KB |
testcase_07 | AC | 92 ms
83,328 KB |
testcase_08 | AC | 44 ms
54,400 KB |
testcase_09 | AC | 44 ms
54,272 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 44 ms
54,016 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 75 ms
73,984 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 47 ms
54,272 KB |
testcase_20 | WA | - |
testcase_21 | AC | 97 ms
78,720 KB |
testcase_22 | WA | - |
testcase_23 | AC | 44 ms
54,400 KB |
testcase_24 | WA | - |
testcase_25 | AC | 44 ms
54,528 KB |
testcase_26 | AC | 64 ms
68,864 KB |
testcase_27 | AC | 107 ms
77,876 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 154 ms
85,632 KB |
ソースコード
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 F[i][j]%2==(L-1)%2 and F2[i][j]<=K-R and F2[i][j]%2==(K-R)%2 and i+1<H and MAP[i+1][j]=="." and i>=1 and MAP[i-1][j]==".": gx,gy=i,j if F[i][j]<=L-1 and F[i][j]%2==(L-1)%2 and F2[i][j]<=K-R and F2[i][j]%2==(K-R)%2 and j+1<W and MAP[i][j+1]=="." and j>=1 and MAP[i][j-1]==".": 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]=="." and gx>=1 and MAP[gx-1][gy]==".": ANS3=["D","U"]*((R-L+1)//2) elif gy+1<W and MAP[gx][gy+1]=="." and gy>=1 and MAP[gx][gy-1]==".": ANS3=["R","L"]*((R-L+1)//2) else: print("No") exit() ANS=ANS1+ANS3+ANS2 print("Yes") print("".join(ANS))