結果
問題 | No.367 ナイトの転身 |
ユーザー | maspy |
提出日時 | 2020-03-19 13:29:35 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,427 bytes |
コンパイル時間 | 117 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 172,976 KB |
最終ジャッジ日時 | 2024-12-14 03:08:26 |
合計ジャッジ時間 | 14,867 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
17,828 KB |
testcase_01 | AC | 32 ms
172,976 KB |
testcase_02 | AC | 32 ms
17,696 KB |
testcase_03 | AC | 33 ms
10,752 KB |
testcase_04 | AC | 29 ms
11,008 KB |
testcase_05 | AC | 29 ms
11,136 KB |
testcase_06 | AC | 30 ms
11,008 KB |
testcase_07 | AC | 28 ms
10,880 KB |
testcase_08 | AC | 30 ms
10,880 KB |
testcase_09 | AC | 30 ms
10,880 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 1,469 ms
70,656 KB |
testcase_13 | AC | 1,448 ms
71,680 KB |
testcase_14 | AC | 1,395 ms
68,480 KB |
testcase_15 | AC | 70 ms
12,672 KB |
testcase_16 | AC | 1,248 ms
61,824 KB |
testcase_17 | AC | 173 ms
16,640 KB |
testcase_18 | AC | 227 ms
19,712 KB |
testcase_19 | AC | 397 ms
26,880 KB |
testcase_20 | AC | 203 ms
18,304 KB |
testcase_21 | AC | 403 ms
26,240 KB |
testcase_22 | AC | 31 ms
10,880 KB |
testcase_23 | AC | 46 ms
11,648 KB |
testcase_24 | AC | 55 ms
11,776 KB |
testcase_25 | AC | 43 ms
11,392 KB |
testcase_26 | AC | 33 ms
169,260 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools from collections import deque H, W = map(int, readline().split()) S = ''.join(read().decode().split()) start = S.index('S') goal = S.index('G') N = H * W Knight = ((2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)) Bishop = ((1, 1), (-1, 1), (-1, -1), (1, -1)) # 0 <= i < N:knightで出発 # N <= i < 2N:bishopで出発 graph = [[] for _ in range(N + N)] for x, y in itertools.product(range(H), range(W)): for dx, dy in Knight: x1 = x + dx y1 = y + dy if not ((0 <= x1 < H) and (0 <= y1 < W)): continue i = x * W + y j = x1 * W + y1 if S[j] == 'R': j += N graph[i].append(j) for dx, dy in Bishop: x1 = x + dx y1 = y + dy if not ((0 <= x1 < H) and (0 <= y1 < W)): continue i = x * W + y + N j = x1 * W + y1 if S[j] != 'R': j += N graph[i].append(j) INF = 10 ** 6 dist = [INF] * (N + N) dist[start] = 0 q = deque([start]) while q: v = q.popleft() dw = dist[v] + 1 for w in graph[v]: if dist[w] <= dw: continue dist[w] = dw q.append(w) answer = min(dist[goal], dist[goal + N]) if answer == INF: answer = -1 print(answer)