結果
| 問題 |
No.496 ワープクリスタル (給料日前編)
|
| ユーザー |
mogurocker
|
| 提出日時 | 2017-10-16 16:14:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,169 bytes |
| コンパイル時間 | 1,355 ms |
| コンパイル使用メモリ | 163,720 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 20:54:03 |
| 合計ジャッジ時間 | 2,191 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 4 WA * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;
pair<int, P> dp[55][55];
int gx, gy, n, f;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin >> gx >> gy >> n >> f;
FOR(i, n+1) FOR(j, n+1) dp[i][j] = {gx+gy, {0, 0}};
for (int i = 1; i <= n; i++) {
int dx, dy, c;
cin >> dx >> dy >> c;
for (int j = 0; j <= i; j++) {
if (dp[i][j].first > dp[i-1][j].first) {
dp[i][j] = {dp[i-1][j].first, {dp[i-1][j].second.first, dp[i-1][j].second.second}};
}
if (j == 0) continue;
int px = dp[i-1][j-1].second.first, py = dp[i-1][j-1].second.second;
int nx = px + dx, ny = py + dy;
if (nx > gx || ny > gy) continue;
if (dp[i][j].first > dp[i-1][j-1].first - abs(gx-px) - abs(gy-py) + c + abs(gx-nx) + abs(gy-ny)) {
dp[i][j] = {dp[i-1][j-1].first - abs(gx-px) - abs(gy-py) + c + abs(gx-nx) + abs(gy-ny), {nx, ny}};
}
}
}
sort(dp[n], dp[n]+n+1);
cout << dp[n][0].first << endl;
return 0;
}
mogurocker