結果
問題 | No.2411 Reverse Directions |
ユーザー | titia |
提出日時 | 2023-08-12 03:17:23 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,023 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 13,312 KB |
実行使用メモリ | 49,664 KB |
最終ジャッジ日時 | 2024-11-18 23:38:25 |
合計ジャッジ時間 | 13,336 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,136 KB |
testcase_01 | AC | 31 ms
11,136 KB |
testcase_02 | AC | 30 ms
11,136 KB |
testcase_03 | AC | 31 ms
11,136 KB |
testcase_04 | AC | 55 ms
22,784 KB |
testcase_05 | AC | 31 ms
11,136 KB |
testcase_06 | AC | 31 ms
11,136 KB |
testcase_07 | AC | 148 ms
19,200 KB |
testcase_08 | AC | 31 ms
11,136 KB |
testcase_09 | AC | 31 ms
11,136 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 28 ms
11,136 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 73 ms
12,288 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 33 ms
11,008 KB |
testcase_20 | WA | - |
testcase_21 | AC | 318 ms
20,096 KB |
testcase_22 | WA | - |
testcase_23 | AC | 30 ms
11,136 KB |
testcase_24 | WA | - |
testcase_25 | AC | 30 ms
11,136 KB |
testcase_26 | AC | 66 ms
11,904 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
ソースコード
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 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 F2[i][j]<=K-R 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))