結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー feybkfeybk
提出日時 2017-06-13 13:11:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,249 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 65,224 KB
実行使用メモリ 8,060 KB
最終ジャッジ日時 2023-10-24 21:45:53
合計ジャッジ時間 1,360 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,056 KB
testcase_01 AC 4 ms
8,056 KB
testcase_02 AC 4 ms
8,056 KB
testcase_03 AC 4 ms
8,056 KB
testcase_04 AC 3 ms
8,056 KB
testcase_05 AC 4 ms
8,056 KB
testcase_06 AC 4 ms
8,056 KB
testcase_07 AC 4 ms
8,056 KB
testcase_08 AC 5 ms
8,060 KB
testcase_09 AC 6 ms
8,060 KB
testcase_10 AC 3 ms
8,060 KB
testcase_11 AC 4 ms
8,060 KB
testcase_12 AC 4 ms
8,060 KB
testcase_13 AC 4 ms
8,060 KB
testcase_14 AC 4 ms
8,056 KB
testcase_15 AC 4 ms
8,056 KB
testcase_16 AC 4 ms
8,060 KB
testcase_17 AC 4 ms
8,060 KB
testcase_18 AC 3 ms
8,056 KB
testcase_19 AC 3 ms
8,056 KB
testcase_20 AC 3 ms
8,056 KB
testcase_21 AC 3 ms
8,056 KB
testcase_22 AC 4 ms
8,060 KB
testcase_23 AC 5 ms
8,060 KB
testcase_24 AC 4 ms
8,060 KB
testcase_25 AC 5 ms
8,060 KB
testcase_26 AC 4 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
int main(){
  int gx,gy,n,f;
  cin >> gx >> gy >> n >> f;
  vector<pair<int, int>> dist(n);
  vector<int> c(n);
  for(int i=0;i<n;i++){
    cin >> dist[i].first >> dist[i].second >> c[i];
  }

  ll dp[53][103][103];
  // for(int j=0;j<=gy;j++){
  //     dp[0][j][0] = j*f;
  // }
  // for(int i=0;i<=gx;i++){
  //     dp[0][0][i] = i*f;
  // }
  for(int i=0;i<=gx;i++){
    for(int j=0;j<=gy;j++){
      dp[0][i][j] = f*(i+j);
    }
  }


  for(int k=0;k<n;k++){
    for(int i=0;i<=gx;i++){
      for(int j=0;j<=gy;j++){
        dp[k+1][i][j] = dp[k][i][j];
        if(i < dist[k].first || j < dist[k].second){
          // no way that we have used a crystal one step before.
          continue;
        }else{
          dp[k+1][i][j] = min(dp[k][i-dist[k].first][j-dist[k].second]+c[k],
                            dp[k+1][i][j]);
        }
      }
    }
  }
  // cout << endl;
  // for(int k=0;k<=n;k++){
  //   for(int j=gy;j>=0;j--){
  //     for(int i=0;i<=gx;i++){
  //       cout << dp[k][i][j] << " ";
  //     }
  //     cout << endl;
  //   }
  //   cout << endl;
  // }
  cout << dp[n][gx][gy] << endl;
  return 0;

}
0