結果

問題 No.496 ワープクリスタル (給料日前編)
コンテスト
ユーザー qib
提出日時 2022-12-10 00:03:56
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 135 ms / 2,000 ms
+ 771µs
コード長 521 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 93 ms
コンパイル使用メモリ 65,580 KB
実行使用メモリ 78,420 KB
最終ジャッジ日時 2026-10-14 20:16:46
合計ジャッジ時間 3,255 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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)
0