結果

問題 No.367 ナイトの転身
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-07 17:55:49
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 950 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2024-04-15 13:38:03
合計ジャッジ時間 7,964 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,816 KB
testcase_01 AC 12 ms
6,944 KB
testcase_02 AC 12 ms
6,944 KB
testcase_03 AC 12 ms
6,940 KB
testcase_04 AC 12 ms
6,944 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 12 ms
6,944 KB
testcase_07 AC 11 ms
6,940 KB
testcase_08 AC 11 ms
6,940 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 1,735 ms
41,344 KB
testcase_11 TLE -
testcase_12 AC 230 ms
19,712 KB
testcase_13 AC 279 ms
19,840 KB
testcase_14 AC 631 ms
19,200 KB
testcase_15 AC 28 ms
6,944 KB
testcase_16 AC 616 ms
17,792 KB
testcase_17 AC 96 ms
7,680 KB
testcase_18 AC 138 ms
8,320 KB
testcase_19 AC 133 ms
9,856 KB
testcase_20 AC 41 ms
7,936 KB
testcase_21 AC 139 ms
9,728 KB
testcase_22 AC 12 ms
6,940 KB
testcase_23 AC 16 ms
6,940 KB
testcase_24 AC 23 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
testcase_26 AC 15 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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))
            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
0