結果
問題 |
No.1037 exhausted
|
ユーザー |
|
提出日時 | 2020-04-25 05:29:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 3,206 ms |
コンパイル使用メモリ | 194,280 KB |
最終ジャッジ日時 | 2025-01-10 00:51:18 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | int n,V,L; scanf("%d%d%d",&n,&V,&L); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:13:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | rep(i,n) scanf("%d%d%d",&x[i],&v[i],&w[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; const long long INF=1LL<<61; int main(){ int n,V,L; scanf("%d%d%d",&n,&V,&L); vector<int> x(n+1),v(n+1),w(n+1); rep(i,n) scanf("%d%d%d",&x[i],&v[i],&w[i]); x[n]=L; // dp[i][j] = ( i 番目のガソリンスタンドまで行って, 残りガソリンが j リットルあるときの最小コスト) static lint dp[2002][2001]; rep(i,n+2) rep(j,V+1) dp[i][j]=INF; dp[0][V]=0; rep(i,n+1){ int j0; if(i==0) j0=x[0]; else j0=x[i]-x[i-1]; for(int j=j0;j<=V;j++){ // i 番目のガソリンスタンドで補充しない dp[i+1][j-j0]=min(dp[i+1][j-j0],dp[i][j]); // 補充する dp[i+1][min(j-j0+v[i],V)]=min(dp[i+1][min(j-j0+v[i],V)],dp[i][j]+w[i]); } } lint ans=*min_element(dp[n+1],dp[n+1]+V+1); printf("%lld\n",ans<INF?ans:-1); return 0; }