結果

問題 No.2411 Reverse Directions
ユーザー 👑 timitimi
提出日時 2024-02-17 11:08:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,114 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 176,892 KB
最終ジャッジ日時 2024-02-17 11:08:44
合計ジャッジ時間 7,455 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,604 KB
testcase_01 AC 44 ms
61,776 KB
testcase_02 AC 44 ms
55,604 KB
testcase_03 AC 41 ms
55,604 KB
testcase_04 WA -
testcase_05 AC 43 ms
55,604 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 41 ms
55,604 KB
testcase_09 AC 40 ms
55,604 KB
testcase_10 WA -
testcase_11 AC 42 ms
55,604 KB
testcase_12 AC 295 ms
125,992 KB
testcase_13 AC 153 ms
88,124 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 80 ms
77,828 KB
testcase_17 AC 153 ms
93,492 KB
testcase_18 AC 140 ms
109,064 KB
testcase_19 AC 58 ms
75,416 KB
testcase_20 AC 151 ms
90,000 KB
testcase_21 AC 135 ms
93,248 KB
testcase_22 AC 233 ms
118,936 KB
testcase_23 AC 168 ms
98,496 KB
testcase_24 AC 297 ms
120,628 KB
testcase_25 AC 86 ms
80,716 KB
testcase_26 AC 83 ms
77,848 KB
testcase_27 AC 144 ms
87,540 KB
testcase_28 WA -
testcase_29 AC 335 ms
173,492 KB
testcase_30 AC 257 ms
147,136 KB
testcase_31 AC 224 ms
113,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W,K,L,R=map(int, input().split())
A=[]
for i in range(H):
  S=input()
  A.append(S)
  
from collections import deque
d=deque()
B=[[10**10]*W for i in range(H)]
B[0][0]=0;BB={}
d.append((0,0))
dy,dx=[0,0,1,-1,],[1,-1,0,0]
for i in range(L-1):
  nd=deque()
  while d:
    y,x=d.popleft()
    for i in range(4):
      ny,nx=y+dy[i],x+dx[i]
      if 0<=ny<H and 0<=nx<W and A[ny][nx]=='.':
        if B[ny][nx]>B[y][x]+1:
          nd.append((ny,nx))
          B[ny][nx]=B[y][x]+1
          BB[(ny,nx)]=(y,x)
  d=nd

d=deque()
C=[[10**10]*W for i in range(H)]
C[H-1][W-1]=0;CC={}
d.append((H-1,W-1))
dy,dx=[0,0,1,-1],[1,-1,0,0]
for i in range(K-R):
  nd=deque()
  while d:
    y,x=d.popleft()
    for i in range(4):
      ny,nx=y+dy[i],x+dx[i]
      if 0<=ny<H and 0<=nx<W and A[ny][nx]=='.':
        if C[ny][nx]>C[y][x]+1:
          nd.append((ny,nx))
          C[ny][nx]=C[y][x]+1
          CC[(ny,nx)]=(y,x)
  d=nd

if (R-L)%2==0:
  print('No')
  exit()
hh,ww=-1,-1;d=0
for h in range(H):
  for w in range(W):
    if B[h][w]!=10**10 and C[h][w]!=10**10:
      if B[h][w]%2==(L-1)%2 and C[h][w]%2==(K-R)%2:
        if h==w==0 or (h==H-1 and w==W-1):
          continue
        hh,ww=h,w


if hh==-1:
  print('No')
  exit()
  
X,Y=[(hh+1,ww+1)],[]
nowy,nowx=hh,ww 
for i in range(B[hh][ww]):
  nowy,nowx=BB[(nowy,nowx)] 
  X.append((nowy+1,nowx+1))
nowy,nowx=hh,ww 
for i in range(C[hh][ww]):
  nowy,nowx=CC[(nowy,nowx)] 
  Y.append((nowy+1,nowx+1))
X=X[::-1]

c=len(X)
if L-c>0:
  if c<=1:
    X.append(Y[0])
    X.append(X[-2])
    for i in range(L-c-2):
      X.append(X[-2])
  else:
    for i in range(L-c):
      X.append(X[-2])
c=len(Y)
if K-R-c>0:
  if c<=1:
    Y.append(X[-1])
    Y.append(Y[-2])
    for i in range(K-R-c-2):
      Y.append(Y[-2])
  else:
    for i in range(K-R-c):
      Y.append(Y[-2])

for i in range((R-L+1)//2):
  X.append(Y[0])
  X.append(X[-2])

ans=[];XX=X+Y
for i in range(len(XX)-1):
  p,q=XX[i];r,s=XX[i+1]
  if q+1==s:
    ans.append('R')
  elif q-1==s:
    ans.append('L')
  elif p+1==r:
    ans.append('D')
  else:
    ans.append('U')
print('Yes')
print(''.join(ans))


    
0