結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
![]() |
提出日時 | 2017-04-02 18:58:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 560 ms / 2,000 ms |
コード長 | 1,653 bytes |
コンパイル時間 | 123 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-07-08 00:11:51 |
合計ジャッジ時間 | 5,979 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
# coding: utf-8 import sys def array2d(d1, d2, init = None): return [[init for _ in range(d2)] for _ in range(d1)] def solve(Gx, Gy, N, F, X, Y, C): dp_layer = array2d(Gx + 1, Gy + 1) dp_prev_layer = None for i in range(-1, N): for x in range(Gx + 1): for y in range(Gy + 1): if x == 0 and y == 0: dp_layer[0][0] = 0 else: cand = [] if x > 0: cand.append(dp_layer[x-1][y] + F) if y > 0: cand.append(dp_layer[x][y-1] + F) if i >= 0: cand.append(dp_prev_layer[x][y]) if x > 0: cand.append(dp_prev_layer[x-1][y] + F) if y > 0: cand.append(dp_prev_layer[x][y-1] + F) if x >= X[i] and y >= Y[i]: cand.append(dp_prev_layer[x - X[i]][y - Y[i]] + C[i]) dp_layer[x][y] = min(cand) dp_prev_layer = dp_layer dp_layer = array2d(Gx + 1, Gy + 1) # # dbg # sys.stderr.write("------\n{} ------\n".format(i)) # for x in range(Gx + 1): # sys.stderr.write(" ".join(["{:2d}".format(cost) for cost in dp_prev_layer[x]]) + "\n") return dp_prev_layer[-1][-1] def main(): Gx, Gy, N, F = map(int, input().split()) x = [None] * N y = [None] * N c = [None] * N for i in range(N): x[i], y[i], c[i] = map(int, input().split()) print(solve(Gx, Gy, N, F, x, y, c)) main()