結果
| 問題 | No.367 ナイトの転身 |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2016-05-07 17:55:49 |
| 言語 | PyPy2 (7.3.20) |
| 結果 |
AC
|
| 実行時間 | 346 ms / 2,000 ms |
| コード長 | 950 bytes |
| 記録 | |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 77,780 KB |
| 最終ジャッジ日時 | 2025-12-03 20:36:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
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))
arrived[i][j][0]=0
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)]]
#cnt=0
while len(state)!=0:
#print "now",cnt,":",len(state)
nextState=[]
for (p,s,x,y) in state:
if B[x][y]=='G':
print p
exit()
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
arrived[nx][ny][ns]=p+1
nextState.append((p+1,ns,nx,ny))
state=nextState
# cnt+=1
print -1
yaoshimax