結果

問題 No.1037 exhausted
ユーザー tko919tko919
提出日時 2020-04-27 18:19:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 166,604 KB
実行使用メモリ 35,264 KB
最終ジャッジ日時 2023-08-14 07:06:15
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
35,012 KB
testcase_01 AC 11 ms
34,952 KB
testcase_02 AC 11 ms
35,012 KB
testcase_03 AC 11 ms
35,076 KB
testcase_04 AC 11 ms
35,112 KB
testcase_05 AC 12 ms
35,004 KB
testcase_06 AC 11 ms
35,116 KB
testcase_07 AC 11 ms
35,044 KB
testcase_08 AC 12 ms
35,052 KB
testcase_09 AC 12 ms
35,008 KB
testcase_10 AC 11 ms
35,040 KB
testcase_11 AC 12 ms
35,072 KB
testcase_12 AC 24 ms
35,092 KB
testcase_13 AC 24 ms
35,060 KB
testcase_14 AC 24 ms
35,064 KB
testcase_15 AC 24 ms
35,224 KB
testcase_16 AC 25 ms
35,100 KB
testcase_17 AC 25 ms
35,092 KB
testcase_18 AC 25 ms
35,164 KB
testcase_19 AC 26 ms
35,020 KB
testcase_20 AC 16 ms
35,156 KB
testcase_21 AC 12 ms
35,220 KB
testcase_22 AC 16 ms
35,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
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;}
//end

ll dp[2010][2010];

int main(){
   int n,v,l; scanf("%d%d%d",&n,&v,&l);
   vector<int> x(n+1),y(n),z(n); x[n]=l;
   rep(i,0,n)scanf("%d%d%d",&x[i],&y[i],&z[i]);
   rep(i,0,2010)rep(j,0,2010)dp[i][j]=INF;
   if(v-x[0]>=0)dp[0][v-x[0]]=0; else{puts("-1"); return 0;}
   rep(i,0,n)rep(j,0,v+1)if(dp[i][j]!=INF){
      if(j-x[i+1]+x[i]>=0)chmin(dp[i+1][j-x[i+1]+x[i]],dp[i][j]);
      if(min(v,j+y[i])-x[i+1]+x[i]>=0)chmin(dp[i+1][min(v,j+y[i])-x[i+1]+x[i]],dp[i][j]+z[i]);
   }
   ll res=INF;
   rep(i,0,v+1)chmin(res,dp[n][i]);
   printf(res==INF?"-1\n":"%lld\n",res);
   return 0;
}
0