結果
問題 | No.2366 登校 |
ユーザー |
![]() |
提出日時 | 2023-06-30 04:41:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,455 ms / 4,000 ms |
コード長 | 1,039 bytes |
コンパイル時間 | 1,578 ms |
コンパイル使用メモリ | 81,980 KB |
実行使用メモリ | 145,040 KB |
最終ジャッジ日時 | 2025-06-20 10:24:52 |
合計ジャッジ時間 | 24,662 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
import heapq n, m, k, t = map(int,input().split()) modoru = [[(-1,-1) for j in range(m)] for i in range(n)] for i in range(k): a, b, c, d = map(int,input().split()) a -= 1 b -= 1 modoru[a][b] = (c, d) tmax = 601 d = [10 ** 18] * n * m * tmax d[200] = 0 pq = [(d[200], 200)] r1 = m * tmax while pq: tmp, nowv = heapq.heappop(pq) fnv = nowv nowt = nowv % tmax nowv //= tmax b = nowv % m a = nowv // m if tmp > d[fnv]: continue for xx, yy in [(-1, 0), (1, 0), (0, 1), (0, -1)]: x = a + xx y = b + yy if 0 <= x < n and 0 <= y < m: dist = tmp targ = x*r1 + y*tmax + min(nowt+1, tmax-1) if dist < d[targ]: d[targ] = dist heapq.heappush(pq, (dist, targ)) if modoru[a][b][0] == -1: continue c, dd = modoru[a][b] dist = tmp + dd targ = a*r1 + b*tmax + max(0, nowt-c+1) if dist < d[targ]: d[targ] = dist heapq.heappush(pq, (dist, targ)) ans = 10 ** 18 for ts in range(tmax): if ts - 200 > t: continue ans = min(ans, d[(n-1)*r1 + (m-1)*tmax + ts]) if ans == 10 ** 18: print(-1) else: print(ans)