結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2016-05-07 17:39:36 |
| 言語 | Python2 (2.7.18) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 855 bytes |
| コンパイル時間 | 542 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 145,528 KB |
| 最終ジャッジ日時 | 2024-10-05 10:20:48 |
| 合計ジャッジ時間 | 3,978 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 1 -- * 16 |
ソースコード
H,W=map(int,raw_input().split())
B=[raw_input() for i in range(H)]
arrived=[[[-1 for i in range(2)] for j in range(W)] for k in range(H)]
state=[]
for i in range(H):
for j in range(W):
if B[i][j]=='S':
state.append((0,0,i,j))
moves=[[(1,2),(2,1),(2,-1),(1,-2),(-1,-2),(-2,-1),(-2,1),(-1,2)],[(1,1),(-1,1),(-1,-1),(1,-1)]]
while len(state)!=0:
nextState=[]
for (p,s,x,y) in state:
if B[x][y]=='G':
print p
exit()
arrived[x][y][s]=p
for (dx,dy) in moves[s]:
nx,ny=x+dx,y+dy
if nx<0 or ny <0 or nx>=H or ny >= W:
continue
ns=s
if B[nx][ny]=='R':
ns=1-s
if arrived[nx][ny][ns]!=-1:
continue
nextState.append((p+1,ns,nx,ny))
state=nextState
print -1
yaoshimax