結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
|
提出日時 | 2017-04-18 10:31:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,104 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 75,604 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 07:35:17 |
合計ジャッジ時間 | 1,293 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>#include <utility>using namespace std;const int inf = 1e9;void show(vector<vector<int>> &vv) {cout << "------" << endl;for (auto v : vv) {for (auto e : v) {if (e == inf) {printf("inf ");} else {printf("%3d ", e);}}printf("\n");}}int main() {int gx, gy, n, f;cin >> gx >> gy >> n >> f;vector<vector<int>> board(gy + 1, vector<int>(gx + 1, inf));board[0][0] = 0;int x, y, c;for (int i = 0; i < n; i++) {cin >> x >> y >> c;if (c >= (x + y) * f) {continue;}for (int j = gy; j >= 0; j--) {for (int k = gx; k >= 0; k--) {if (board[j][k] == inf) {continue;}int nx = k + x;int ny = j + y;if (nx > gx || ny > gy) {continue;}board[ny][nx] = min(board[ny][nx], board[j][k] + c);// show(board);}}}// show(board);int ans = inf;for (int i = 0; i <= gy; i++) {for (int j = 0; j <= gx; j++) {ans = min(ans, (gy + gx - i - j) * f + board[i][j]);}}cout << ans << endl;return 0;}