結果
| 問題 | No.496 ワープクリスタル (給料日前編) |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-09-08 15:23:08 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 2,007 bytes |
| 記録 | |
| コンパイル時間 | 4,700 ms |
| コンパイル使用メモリ | 149,504 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-31 18:46:40 |
| 合計ジャッジ時間 | 6,160 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
コンパイルメッセージ
main.cpp:40:25: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
40 | int dp[N + 1][GY + 1][GX + 1];
| ^~~~~~
main.cpp:40:25: note: read of non-const variable 'GX' is not allowed in a constant expression
main.cpp:29:7: note: declared here
29 | int GX, GY, N, F;
| ^
main.cpp:40:17: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
40 | int dp[N + 1][GY + 1][GX + 1];
| ^~~~~~
main.cpp:40:17: note: read of non-const variable 'GY' is not allowed in a constant expression
main.cpp:29:11: note: declared here
29 | int GX, GY, N, F;
| ^
main.cpp:40:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
40 | int dp[N + 1][GY + 1][GX + 1];
| ^~~~~
main.cpp:40:10: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:29:15: note: declared here
29 | int GX, GY, N, F;
| ^
3 warnings generated.
ソースコード
#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