結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー |
![]() |
提出日時 | 2017-03-24 22:45:08 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 1,582 bytes |
コンパイル時間 | 872 ms |
コンパイル使用メモリ | 90,884 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-07-05 22:11:14 |
合計ジャッジ時間 | 1,647 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <algorithm>#include <cfloat>#include <climits>#include <cmath>#include <complex>#include <cstdio>#include <cstdlib>#include <cstring>#include <functional>#include <iostream>#include <map>#include <memory>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <utility>#include <vector>using namespace std;typedef long long ll;#define sz size()#define pb push_back#define mp make_pair#define fi first#define se second#define all(c) (c).begin(), (c).end()#define rep(i,a,b) for(ll i=(a);i<(b);++i)#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)#define clr(a, b) memset((a), (b) ,sizeof(a))#define ctos(c) string(1,c)#define print(x) cout<<#x<<" = "<<x<<endl;#define MOD 1000000007ll dp[55][110][110];int main(){ll gx,gy,n,f;cin>>gx>>gy>>n>>f;vector<ll> vx;vector<ll> vy;vector<ll> vc;rep(i,0,n){ll a,b,c;cin>>a>>b>>c;vx.pb(a);vy.pb(b);vc.pb(c);}rep(i,0,55)rep(j,0,110)rep(k,0,110)dp[i][j][k] = 1000000000000LL;dp[0][0][0] = 0;rep(i,1,vx.sz+1){rep(j,0,105){rep(k,0,105){if(dp[i-1][j][k]!=-1){dp[i][min(103LL,j+vx[i-1])][min(103LL,k+vy[i-1])] = min(dp[i][min(103LL,j+vx[i-1])][min(103LL,k+vy[i-1])],dp[i-1][j][k]+vc[i-1]);dp[i][j][k] = min(dp[i][j][k],dp[i-1][j][k]);}}}}ll mn = 1000000000000LL;rep(x,0,gx+1){rep(y,0,gy+1){if(dp[n][x][y]!=-1){mn = min(mn,dp[n][x][y]+(abs(gx-x)+abs(gy-y))*f);}}}cout << mn << endl;return 0;}