結果
問題 | No.614 壊れたキャンパス |
ユーザー | mkawa2 |
提出日時 | 2020-06-04 22:13:18 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,372 bytes |
コンパイル時間 | 784 ms |
コンパイル使用メモリ | 87,264 KB |
実行使用メモリ | 263,144 KB |
最終ジャッジ日時 | 2023-08-20 07:29:51 |
合計ジャッジ時間 | 14,686 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
71,668 KB |
testcase_01 | AC | 91 ms
71,096 KB |
testcase_02 | AC | 90 ms
71,176 KB |
testcase_03 | AC | 92 ms
71,068 KB |
testcase_04 | AC | 93 ms
71,096 KB |
testcase_05 | AC | 86 ms
71,148 KB |
testcase_06 | AC | 91 ms
71,356 KB |
testcase_07 | AC | 89 ms
71,376 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | AC | 1,325 ms
240,476 KB |
testcase_11 | AC | 1,604 ms
243,452 KB |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | AC | 1,922 ms
242,108 KB |
testcase_15 | AC | 1,574 ms
234,536 KB |
testcase_16 | AC | 1,948 ms
236,132 KB |
testcase_17 | AC | 1,170 ms
263,144 KB |
testcase_18 | AC | 1,320 ms
226,220 KB |
testcase_19 | AC | 720 ms
218,452 KB |
ソースコード
from heapq import * import sys def MI(): return map(int, sys.stdin.readline().split()) def main(): n, m, k, s, t = MI() abc = [] floor = [set() for _ in range(n)] floor[0].add(s) floor[n - 1].add(t) for _ in range(m): a, b, c = MI() floor[a - 1].add(b) floor[a].add(c) abc.append((a-1, b, c)) iftou = {} u = 0 for i in range(n): for f in floor[i]: iftou[i, f] = u u += 1 un = u s = iftou[0, s] t = iftou[n - 1, t] to = [[] for _ in range(un)] for a, b, c in abc: u = iftou[a, b] v = iftou[a + 1, c] to[u].append((v, 0)) for i in range(n): v = -1 pf = -1 for f in sorted(floor[i]): if v == -1: v = iftou[i, f] pf = f continue u = iftou[i, f] cost = f - pf to[u].append((v, cost)) to[v].append((u, cost)) v = u pf = f hp = [] heappush(hp, (0, s)) dist = [-1] * un while hp: d, u = heappop(hp) if u == t: print(d) exit() if dist[u] != -1: continue dist[u] = d for v, cost in to[u]: if dist[v] != -1: continue heappush(hp, (d + cost, v)) print(-1) main()