結果

問題 No.367 ナイトの転身
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-07 17:39:36
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 855 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 138,480 KB
最終ジャッジ日時 2024-04-15 13:37:48
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
11,648 KB
testcase_01 AC 12 ms
6,272 KB
testcase_02 AC 11 ms
6,272 KB
testcase_03 AC 12 ms
6,272 KB
testcase_04 AC 12 ms
6,400 KB
testcase_05 AC 11 ms
6,272 KB
testcase_06 AC 13 ms
6,400 KB
testcase_07 AC 11 ms
6,272 KB
testcase_08 AC 12 ms
6,272 KB
testcase_09 AC 11 ms
6,272 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0