結果
| 問題 |
No.496 ワープクリスタル (給料日前編)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-01 17:05:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 2,072 bytes |
| コンパイル時間 | 1,145 ms |
| コンパイル使用メモリ | 118,772 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-09-18 20:06:33 |
| 合計ジャッジ時間 | 2,174 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll dp[150][150][70];
ll dh[2] = { 1,0 };
ll dw[2] = { 0,1 };
int main()
{
/*
cin.tie(nullptr);
ios::sync_with_stdio(false);
*/
ll gh, gw, n, f; scanf("%lld %lld %lld %lld", &gh, &gw, &n, &f);
ll H = gh + 1;
ll W = gw + 1;
vector<ll> x(n), y(n), c(n);
for (ll i = 0; i < n; i++) scanf("%lld %lld %lld", &x[i], &y[i], &c[i]);
for (ll i = 0; i <= gh; i++)for (ll j = 0; j <= gw; j++)for (ll k = 0; k <= n; k++) dp[i][j][k] = INF;
dp[0][0][0] = 0;
for (ll k = 0; k <= n; k++) {
for (ll i = 0; i <= gh; i++) {
for (ll j = 0; j <= gw; j++) {
for (ll l = 0; l < 2; l++) {
ll nh = i + dh[l];
ll nw = j + dw[l];
if (nh >= H || nw >= W) continue;
chmin(dp[nh][nw][k], dp[i][j][k] + f);
}
}
}
if (k == n)continue;
for (ll i = 0; i <= gh; i++) {
for (ll j = 0; j <= gw; j++) {
for (ll l = 0; l < 2; l++) {
ll nh = i + dh[l];
ll nw = j + dw[l];
if (nh >= H || nw >= W) continue;
chmin(dp[nh][nw][k + 1], dp[i][j][k] + f);
}
chmin(dp[i][j][k + 1], dp[i][j][k]);
ll nh = i + x[k];
ll nw = j + y[k];
if (nh >= H || nw >= W) continue;
chmin(dp[nh][nw][k + 1], dp[i][j][k] + c[k]);
}
}
}
cout << dp[gh][gw][n] << endl;
return 0;
}