結果
問題 | No.367 ナイトの転身 |
ユーザー | 37kt_ |
提出日時 | 2016-05-16 11:43:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 680 ms / 2,000 ms |
コード長 | 943 bytes |
コンパイル時間 | 700 ms |
コンパイル使用メモリ | 87,196 KB |
実行使用メモリ | 111,188 KB |
最終ジャッジ日時 | 2023-08-25 01:38:55 |
合計ジャッジ時間 | 8,930 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 158 ms
80,860 KB |
testcase_01 | AC | 150 ms
80,880 KB |
testcase_02 | AC | 147 ms
80,840 KB |
testcase_03 | AC | 151 ms
80,936 KB |
testcase_04 | AC | 155 ms
80,928 KB |
testcase_05 | AC | 157 ms
80,844 KB |
testcase_06 | AC | 160 ms
81,252 KB |
testcase_07 | AC | 153 ms
80,620 KB |
testcase_08 | AC | 149 ms
80,808 KB |
testcase_09 | AC | 155 ms
80,860 KB |
testcase_10 | AC | 480 ms
107,212 KB |
testcase_11 | AC | 680 ms
111,188 KB |
testcase_12 | AC | 418 ms
94,188 KB |
testcase_13 | AC | 399 ms
94,288 KB |
testcase_14 | AC | 382 ms
93,760 KB |
testcase_15 | AC | 206 ms
83,812 KB |
testcase_16 | AC | 387 ms
92,900 KB |
testcase_17 | AC | 228 ms
84,480 KB |
testcase_18 | AC | 242 ms
85,164 KB |
testcase_19 | AC | 262 ms
86,664 KB |
testcase_20 | AC | 226 ms
84,752 KB |
testcase_21 | AC | 266 ms
86,708 KB |
testcase_22 | AC | 168 ms
82,688 KB |
testcase_23 | AC | 195 ms
83,708 KB |
testcase_24 | AC | 197 ms
83,428 KB |
testcase_25 | AC | 191 ms
83,868 KB |
testcase_26 | AC | 182 ms
83,516 KB |
ソースコード
from queue import Queue dx = [[-2, -2, -1, 1, 2, 2, 1, -1], [-1, -1, 1, 1]] dy = [[-1, 1, 2, 2, 1, -1, -2, -2], [-1, 1, 1, -1]] h, w = map(int, input().split()) s = [input() for i in range(h)] sx, sy, gx, gy = [-1, -1, -1, -1] for i, line in enumerate(s): for j, c in enumerate(line): if c == "S": sx, sy = i, j elif c == "G": gx, gy = i, j dist = [[ [-1, -1] for j in range(w)] for i in range(h)] q = Queue() dist[sx][sy][0] = 0 q.put((sx, sy, 0)) while not q.empty(): x, y, d = q.get() for i in range(len(dx[d])): nx, ny = x + dx[d][i], y + dy[d][i] if nx < 0 or h <= nx or ny < 0 or w <= ny: continue nd = d ^ (1 if s[nx][ny] == "R" else 0) if dist[nx][ny][nd] == -1: dist[nx][ny][nd] = dist[x][y][d] + 1 q.put((nx, ny, nd)) res = -1 if dist[gx][gy][0] == -1: res = dist[gx][gy][1] elif dist[gx][gy][1] == -1: res = dist[gx][gy][0] else: res = min(dist[gx][gy]) print(res)