結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
![]() |
提出日時 | 2017-03-24 23:05:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,652 bytes |
コンパイル時間 | 1,819 ms |
コンパイル使用メモリ | 179,304 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 23:17:11 |
合計ジャッジ時間 | 2,427 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)#define rep(i,n) REP(i,0,n)#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)#define ALLOF(c) (c).begin(), (c).end()typedef long long ll;typedef unsigned long long ull;#define INF 1000000000struct ST {int x, y, c;};int main(){int Gx, Gy, N, F;cin >> Gx >> Gy >> N >> F;vector<ST> v;rep(i,N){int x, y, c;cin >> x >> y >> c;v.push_back((ST){x,y,c});}vector<vector<int>> cost(Gy+1, vector<int>(Gx+1,INF));cost[0][0] = 0;rep(y,cost.size()){rep(x,cost[y].size()){if(y+1<cost.size()){cost[y+1][x] = min(cost[y+1][x], cost[y][x]+F);}if(x+1<cost[y].size()){cost[y][x+1] = min(cost[y][x+1], cost[y][x]+F);}}}rep(i,N){vector<vector<int>> new_cost = cost;rep(y,cost.size()){rep(x,cost[y].size()){if(cost[y][x] != INF){new_cost[y][x] = min(new_cost[y][x], cost[y][x]);if(x+v[i].x<cost[y].size() && y+v[i].y<cost.size()){new_cost[y+v[i].y][x+v[i].x] = min(new_cost[y+v[i].y][x+v[i].x],cost[y][x] + v[i].c);}}}}rep(y,cost.size()){rep(x,cost[y].size()){if(y+1<cost.size()){new_cost[y+1][x] = min(new_cost[y+1][x], new_cost[y][x]+F);}if(x+1<cost[y].size()){new_cost[y][x+1] = min(new_cost[y][x+1], new_cost[y][x]+F);}}}cost = new_cost;}cout << cost[Gy][Gx] << endl;return 0;}