結果
問題 | No.2213 Neq Move |
ユーザー |
|
提出日時 | 2022-10-12 15:47:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,376 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 78,160 KB |
最終ジャッジ日時 | 2024-07-07 15:07:10 |
合計ジャッジ時間 | 1,996 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 1 WA * 4 |
ソースコード
def dijkstra(s, n, graph):INF = 10 ** 18import heapqdist = [INF] * ndist[s] = 0bef = [0] * nbef[s] = shq = [(0, s)]heapq.heapify(hq)visit = [False] * nwhile hq:c, v = heapq.heappop(hq)visit[v] = Trueif c > dist[v]:continuefor to, cost in graph[v]:if visit[to] == False and dist[v] + cost < dist[to]:dist[to] = cost + dist[v]bef[to] = vheapq.heappush(hq, (dist[to], to))return dist, befdef solve(a, b, c, d):ind = {}i = 0for v in [0, 1, a, b, c, d]:for u in [0, 1, a, b, c, d]:if u != v:ind[u, v] = ii += 1graph = [[] for _ in range(i)]for u1, v1 in ind.keys():i1 = ind[u1, v1]for u2, v2 in ind.keys():i2 = ind[u2, v2]if u1 <= u2 and v1 <= v2 and i1 != i2 and ((u1 < v1 and u2 < v2) or (u1 > v1 and u2 > v2)):graph[i1].append((i2, abs(u2 - u1) + abs(v2 - v1)))if (u2 == 0 and v1 == v2) or (v2 == 0 and u1 == u2):graph[i1].append((i2, 1))D, _ = dijkstra(ind[a, b], i, graph)return (D[ind[(c, d)]])for _ in range(int(input())):a, b, c, d = map(int,input().split())print(solve(a, b, c, d))