結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2017-03-24 22:45:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,582 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 88,792 KB
実行使用メモリ 8,868 KB
最終ジャッジ日時 2023-09-20 01:51:15
合計ジャッジ時間 1,744 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,660 KB
testcase_01 AC 4 ms
8,604 KB
testcase_02 AC 4 ms
8,684 KB
testcase_03 AC 4 ms
8,824 KB
testcase_04 AC 4 ms
8,668 KB
testcase_05 AC 5 ms
8,544 KB
testcase_06 AC 5 ms
8,600 KB
testcase_07 AC 4 ms
8,548 KB
testcase_08 AC 6 ms
8,608 KB
testcase_09 AC 6 ms
8,552 KB
testcase_10 AC 6 ms
8,544 KB
testcase_11 AC 7 ms
8,540 KB
testcase_12 AC 6 ms
8,680 KB
testcase_13 AC 6 ms
8,544 KB
testcase_14 AC 5 ms
8,868 KB
testcase_15 AC 4 ms
8,744 KB
testcase_16 AC 5 ms
8,548 KB
testcase_17 AC 5 ms
8,596 KB
testcase_18 AC 4 ms
8,540 KB
testcase_19 AC 4 ms
8,552 KB
testcase_20 AC 4 ms
8,612 KB
testcase_21 AC 5 ms
8,828 KB
testcase_22 AC 6 ms
8,668 KB
testcase_23 AC 6 ms
8,620 KB
testcase_24 AC 6 ms
8,552 KB
testcase_25 AC 6 ms
8,540 KB
testcase_26 AC 6 ms
8,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 1000000007

ll 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;
}
0