結果
| 問題 | No.5015 Escape from Labyrinth | 
| コンテスト | |
| ユーザー |  titia | 
| 提出日時 | 2023-04-16 07:15:23 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,624 bytes | 
| コンパイル時間 | 366 ms | 
| コンパイル使用メモリ | 11,288 KB | 
| 実行使用メモリ | 13,596 KB | 
| スコア | 0 | 
| 最終ジャッジ日時 | 2023-04-16 07:15:33 | 
| 合計ジャッジ時間 | 9,222 ms | 
| ジャッジサーバーID (参考情報) | judge15 / judge11 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | TLE * 1 -- * 99 | 
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
N,D,H=map(int,input().split())
MAP=[]
for i in range(N):
    S=input().strip()
    MAP.append(S)
M=int(input())
T=[list(map(int,input().split())) for i in range(M)]
for i in range(N):
    for j in range(N):
        if MAP[i][j]=="S":
            start=[i,j]
        elif MAP[i][j]=="G":
            goal=[i,j]
        elif MAP[i][j]=="K":
            key=[i,j]
D=[[1<<30]*N for i in range(N)]
U=[[""]*N for i in range(N)]
x,y=start
D[x][y]=0
Q=deque()
Q.append((x,y))
while Q:
    x,y=Q.popleft()
    if x-1>=0 and MAP[x-1][y]!="#" and MAP[x-1][y]!="E"  and D[x-1][y]>D[x][y]+1:
        D[x-1][y]=D[x][y]+1
        Q.append((x-1,y))
        U[x-1][y]="U"
    if x+1<N and MAP[x+1][y]!="#" and MAP[x+1][y]!="E"   and D[x+1][y]>D[x][y]+1:
        D[x+1][y]=D[x][y]+1
        Q.append((x+1,y))
        U[x+1][y]="D"
    if y-1>=0 and MAP[x][y-1]!="#" and MAP[x][y-1]!="E"   and D[x][y-1]>D[x][y]+1:
        D[x][y-1]=D[x][y]+1
        Q.append((x,y-1))
        U[x][y-1]="L"
    if y+1<N and MAP[x][y+1]!="#" and MAP[x][y+1]!="E"   and D[x][y+1]>D[x][y]+1:
        D[x][y+1]=D[x][y]+1
        Q.append((x,y+1))
        U[x][y+1]="D"
x,y=key
ANS=[]
while [x,y]!=start:
    #print(x,y)
    if U[x][y]=="D":
        ANS.append("D")
        x-=1
    elif U[x][y]=="U":
        ANS.append("U")
        x+=1
    elif U[x][y]=="R":
        ANS.append("R")
        y-=1
    elif U[x][y]=="L":
        ANS.append("L")
        y+=1
D=[[1<<30]*N for i in range(N)]
U=[[""]*N for i in range(N)]
x,y=key
D[x][y]=0
Q=deque()
Q.append((x,y))
while Q:
    x,y=Q.popleft()
    if x-1>=0 and MAP[x-1][y]!="#" and MAP[x-1][y]!="E" and D[x-1][y]>D[x][y]+1:
        D[x-1][y]=D[x][y]+1
        Q.append((x-1,y))
        U[x-1][y]="U"
    if x+1<N and MAP[x+1][y]!="#" and MAP[x+1][y]!="E"  and D[x+1][y]>D[x][y]+1:
        D[x+1][y]=D[x][y]+1
        Q.append((x+1,y))
        U[x+1][y]="D"
    if y-1>=0 and MAP[x][y-1]!="#" and MAP[x][y-1]!="E"  and D[x][y-1]>D[x][y]+1:
        D[x][y-1]=D[x][y]+1
        Q.append((x,y-1))
        U[x][y-1]="L"
    if y+1<N and MAP[x][y+1]!="#" and MAP[x][y+1]!="E"  and D[x][y+1]>D[x][y]+1:
        D[x][y+1]=D[x][y]+1
        Q.append((x,y+1))
        U[x][y+1]="D"
x,y=goal
ANS2=[]
while [x,y]!=key:
    #print(x,y)
    if U[x][y]=="D":
        ANS2.append("D")
        x-=1
    elif U[x][y]=="U":
        ANS2.append("U")
        x+=1
    elif U[x][y]=="R":
        ANS2.append("R")
        y-=1
    elif U[x][y]=="L":
        ANS2.append("L")
        y+=1
LANS=ANS[::-1]+ANS2[::-1]
for com in LANS:
    print("M",com)
            
            
            
        