結果
問題 |
No.496 ワープクリスタル (給料日前編)
|
ユーザー |
|
提出日時 | 2022-12-10 00:03:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 521 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 71,936 KB |
最終ジャッジ日時 | 2024-10-14 23:12:34 |
合計ジャッジ時間 | 2,452 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
import heapq INF = 1 << 60 gx, gy, n, f = map(int, input().split()) dp = {} dp[(0, 0)] = 0 for _ in range(n): dx, dy, dc = map(int, input().split()) ndp = {} for cur, c in dp.items(): cx, cy = cur ndp[(cx, cy)] = min(ndp.get((cx, cy), INF), c) nx = cx + dx ny = cy + dy if nx <= gx and ny <= gy: ndp[(nx, ny)] = min(ndp.get((nx, ny), INF), c + dc) dp = ndp ans = INF for diff, cost in dp.items(): dx, dy = diff ans = min(ans, cost + (abs(gx - dx) + abs(gy - dy)) * f) print(ans)