結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー tcltktcltk
提出日時 2021-01-19 01:19:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 89,576 KB
最終ジャッジ日時 2023-08-21 11:17:39
合計ジャッジ時間 9,282 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 250 ms
83,424 KB
testcase_01 AC 239 ms
83,512 KB
testcase_02 AC 242 ms
83,312 KB
testcase_03 AC 239 ms
83,520 KB
testcase_04 AC 239 ms
83,164 KB
testcase_05 AC 242 ms
83,332 KB
testcase_06 AC 247 ms
83,796 KB
testcase_07 AC 239 ms
83,504 KB
testcase_08 AC 291 ms
89,468 KB
testcase_09 AC 288 ms
89,480 KB
testcase_10 AC 264 ms
87,472 KB
testcase_11 AC 259 ms
86,640 KB
testcase_12 AC 264 ms
86,708 KB
testcase_13 AC 272 ms
87,452 KB
testcase_14 AC 267 ms
87,516 KB
testcase_15 AC 265 ms
87,100 KB
testcase_16 AC 270 ms
87,396 KB
testcase_17 AC 275 ms
87,972 KB
testcase_18 AC 272 ms
87,572 KB
testcase_19 AC 270 ms
87,776 KB
testcase_20 AC 274 ms
87,040 KB
testcase_21 AC 263 ms
86,856 KB
testcase_22 AC 291 ms
89,452 KB
testcase_23 AC 292 ms
89,276 KB
testcase_24 AC 289 ms
89,528 KB
testcase_25 AC 289 ms
89,576 KB
testcase_26 AC 292 ms
89,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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