結果
| 問題 |
No.496 ワープクリスタル (給料日前編)
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-09-08 15:23:08 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 2,007 bytes |
| コンパイル時間 | 10,914 ms |
| コンパイル使用メモリ | 142,820 KB |
| 実行使用メモリ | 5,504 KB |
| 最終ジャッジ日時 | 2024-12-26 01:03:14 |
| 合計ジャッジ時間 | 9,247 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
struct Crystal {
int y;
int x;
int c;
Crystal(int y = -1, int x = -1, int c = -1) {
this->y = y;
this->x = x;
this->c = c;
}
};
int main() {
int GX, GY, N, F;
cin >> GX >> GY >> N >> F;
vector<Crystal> crystals;
int x, y, c;
for (int i = 0; i < N; ++i) {
cin >> x >> y >> c;
crystals.push_back(Crystal(y, x, c));
}
int dp[N + 1][GY + 1][GX + 1];
memset(dp, -1, sizeof(dp));
for (int y = 0; y <= GY; ++y) {
for (int x = 0; x <= GX; ++x) {
int dist = y + x;
dp[0][y][x] = F * dist;
}
}
for (int i = 0; i < N; ++i) {
Crystal crystal = crystals[i];
for (int y = 0; y <= GY; ++y) {
for (int x = 0; x <= GX; ++x) {
int ny = y + crystal.y;
int nx = x + crystal.x;
if (dp[i + 1][y][x] == -1) {
dp[i + 1][y][x] = dp[i][y][x];
} else {
dp[i + 1][y][x] = min(dp[i + 1][y][x], dp[i][y][x]);
}
if (0 <= ny && ny <= GY && 0 <= nx && nx <= GX) {
if (dp[i + 1][ny][nx] == -1) {
dp[i + 1][ny][nx] = dp[i][y][x] + crystal.c;
} else {
dp[i + 1][ny][nx] = min(dp[i + 1][ny][nx], dp[i][y][x] + crystal.c);
}
}
if (y + 1 <= GY) {
if (dp[i + 1][y + 1][x] == -1) {
dp[i + 1][y + 1][x] = dp[i][y][x] + F;
} else {
dp[i + 1][y + 1][x] = min(dp[i + 1][y + 1][x], dp[i][y][x] + F);
}
}
if (x + 1 <= GX) {
if (dp[i + 1][y][x + 1] == -1) {
dp[i + 1][y][x + 1] = dp[i][y][x] + F;
} else {
dp[i + 1][y][x + 1] = min(dp[i + 1][y][x + 1], dp[i][y][x] + F);
}
}
}
}
}
cout << dp[N][GY][GX] << endl;
return 0;
}
siman