結果
問題 |
No.1037 exhausted
|
ユーザー |
|
提出日時 | 2020-04-25 05:35:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 2,217 ms |
コンパイル使用メモリ | 194,152 KB |
最終ジャッジ日時 | 2025-01-10 00:51:29 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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+1],&v[i+1],&w[i+1]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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+2),v(n+2),w(n+2); rep(i,n) scanf("%d%d%d",&x[i+1],&v[i+1],&w[i+1]); x[n+1]=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=x[i+1]-x[i]; for(int j=j0;j<=V;j++){ // 補充しない dp[i+1][j-j0]=min(dp[i+1][j-j0],dp[i][j]); // 補充する int j2=min(j-j0+v[i+1],V); dp[i+1][j2]=min(dp[i+1][j2],dp[i][j]+w[i+1]); } } lint ans=*min_element(dp[n+1],dp[n+1]+V+1); printf("%lld\n",ans<INF?ans:-1); return 0; }