結果

問題 No.367 ナイトの転身
ユーザー yaoshimaxyaoshimax
提出日時 2016-05-07 17:56:35
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 77,920 KB
実行使用メモリ 105,172 KB
最終ジャッジ日時 2023-08-25 02:42:29
合計ジャッジ時間 5,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
76,320 KB
testcase_01 AC 71 ms
76,284 KB
testcase_02 AC 70 ms
76,588 KB
testcase_03 AC 69 ms
76,356 KB
testcase_04 AC 69 ms
76,476 KB
testcase_05 AC 68 ms
76,572 KB
testcase_06 AC 76 ms
77,348 KB
testcase_07 AC 71 ms
76,372 KB
testcase_08 AC 70 ms
76,284 KB
testcase_09 AC 70 ms
76,344 KB
testcase_10 AC 240 ms
102,144 KB
testcase_11 AC 314 ms
105,172 KB
testcase_12 AC 121 ms
88,080 KB
testcase_13 AC 133 ms
88,272 KB
testcase_14 AC 166 ms
88,336 KB
testcase_15 AC 101 ms
79,664 KB
testcase_16 AC 169 ms
87,208 KB
testcase_17 AC 110 ms
79,912 KB
testcase_18 AC 104 ms
79,260 KB
testcase_19 AC 103 ms
79,432 KB
testcase_20 AC 96 ms
79,476 KB
testcase_21 AC 112 ms
80,088 KB
testcase_22 AC 80 ms
78,936 KB
testcase_23 AC 88 ms
79,376 KB
testcase_24 AC 90 ms
79,552 KB
testcase_25 AC 92 ms
79,448 KB
testcase_26 AC 84 ms
79,064 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