結果

問題 No.2411 Reverse Directions
ユーザー 👑 timitimi
提出日時 2024-02-17 09:48:37
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,088 bytes
コンパイル時間 484 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 156,648 KB
最終ジャッジ日時 2024-02-17 09:48:46
合計ジャッジ時間 8,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,604 KB
testcase_01 AC 47 ms
61,776 KB
testcase_02 AC 40 ms
55,604 KB
testcase_03 AC 40 ms
55,604 KB
testcase_04 AC 222 ms
133,264 KB
testcase_05 AC 43 ms
55,604 KB
testcase_06 AC 42 ms
55,604 KB
testcase_07 AC 128 ms
80,484 KB
testcase_08 AC 45 ms
55,604 KB
testcase_09 AC 43 ms
55,604 KB
testcase_10 AC 346 ms
148,372 KB
testcase_11 AC 43 ms
55,604 KB
testcase_12 RE -
testcase_13 AC 156 ms
88,024 KB
testcase_14 AC 187 ms
108,768 KB
testcase_15 AC 113 ms
89,308 KB
testcase_16 AC 82 ms
77,828 KB
testcase_17 RE -
testcase_18 AC 154 ms
97,492 KB
testcase_19 AC 61 ms
75,288 KB
testcase_20 RE -
testcase_21 AC 138 ms
93,260 KB
testcase_22 RE -
testcase_23 AC 172 ms
98,496 KB
testcase_24 RE -
testcase_25 AC 88 ms
80,716 KB
testcase_26 AC 108 ms
77,848 KB
testcase_27 AC 136 ms
87,544 KB
testcase_28 AC 253 ms
144,128 KB
testcase_29 RE -
testcase_30 AC 349 ms
156,648 KB
testcase_31 AC 213 ms
113,540 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 0<=h-1<H and 0<=h+1<H and A[h-1][w]==A[h+1][w]=='.':
          hh,ww=h,w;d=1
        if 0<=w-1<W and 0<=w+1<W and A[h][w-1]==A[h][w+1]=='.':
          hh,ww=h,w;d=-1

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=L-len(X)
for i in range(c):
  X.append(X[-2])
c=K-R-len(Y)
for i in range(c):
  Y.append(Y[-2])
  
for i in range(R-L+1):
  p,q=X[-1]
  if d==1:
    if i%2==0:
      X.append((p+1,q))
    else:
      X.append((p-1,q))
  else:
    if i%2==0:
      X.append((p,q+1))
    else:
      X.append((p,q-1))

XX=X+Y 
ans=[]
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