結果
| 問題 |
No.496 ワープクリスタル (給料日前編)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-19 01:19:38 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 186 ms / 2,000 ms |
| コード長 | 1,370 bytes |
| コンパイル時間 | 198 ms |
| コンパイル使用メモリ | 81,876 KB |
| 実行使用メモリ | 90,224 KB |
| 最終ジャッジ日時 | 2024-12-14 21:58:59 |
| 合計ジャッジ時間 | 5,863 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#region Header
#!/usr/bin/env python3
# from typing import *
import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq
def input():
return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
#endregion
# _INPUT = """3 3 2 1
# 1 2 2
# 2 1 2
# """
# sys.stdin = io.StringIO(_INPUT)
def main():
Gx, Gy, N, F = map(int, input().split())
crystals = []
for _ in range(N):
_x, _y, _c = map(int, input().split())
crystals.append((_x, _y, _c))
dp = [[[10**10 for _ in range(Gy+1)] for _ in range(Gx+1)] for _ in range(N+1)]
dp[0][0][0] = 0
for n in range(N):
for x in range(Gx+1):
for y in range(Gy+1):
dp[n+1][x][y] = min(dp[n+1][x][y], dp[n][x][y])
crystal = crystals[n]
x1 = x + crystal[0]
y1 = y + crystal[1]
if x1 <= Gx and y1 <= Gy:
dp[n+1][x1][y1] = min(dp[n+1][x1][y1], dp[n][x][y] + crystal[2])
cost_min = 10**10
for x in range(Gx+1):
for y in range(Gy+1):
d = (Gx - x) + (Gy - y)
cost = dp[N][x][y] + F * d
cost_min = min(cost_min, cost)
print(cost_min)
if __name__ == '__main__':
main()