結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー qibqib
提出日時 2022-12-10 00:03:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 72,112 KB
最終ジャッジ日時 2024-04-22 23:21:04
合計ジャッジ時間 2,303 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,668 KB
testcase_01 AC 33 ms
53,656 KB
testcase_02 AC 34 ms
52,736 KB
testcase_03 AC 33 ms
53,008 KB
testcase_04 AC 34 ms
53,056 KB
testcase_05 AC 35 ms
53,700 KB
testcase_06 AC 33 ms
53,492 KB
testcase_07 AC 37 ms
53,292 KB
testcase_08 AC 53 ms
67,040 KB
testcase_09 AC 50 ms
66,968 KB
testcase_10 AC 46 ms
63,796 KB
testcase_11 AC 43 ms
62,228 KB
testcase_12 AC 45 ms
64,556 KB
testcase_13 AC 44 ms
63,796 KB
testcase_14 AC 45 ms
62,304 KB
testcase_15 AC 39 ms
54,520 KB
testcase_16 AC 40 ms
61,092 KB
testcase_17 AC 40 ms
61,000 KB
testcase_18 AC 35 ms
53,728 KB
testcase_19 AC 36 ms
54,244 KB
testcase_20 AC 35 ms
53,216 KB
testcase_21 AC 37 ms
53,960 KB
testcase_22 AC 51 ms
68,744 KB
testcase_23 AC 52 ms
72,112 KB
testcase_24 AC 50 ms
67,212 KB
testcase_25 AC 44 ms
63,780 KB
testcase_26 AC 48 ms
66,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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