結果
問題 | No.1037 exhausted |
ユーザー |
|
提出日時 | 2020-04-24 22:07:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 795 bytes |
コンパイル時間 | 2,301 ms |
コンパイル使用メモリ | 193,664 KB |
最終ジャッジ日時 | 2025-01-09 23:52:05 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%lld%lld%lld",&x[i],&v[i],&w[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<n;i++) using namespace std; typedef pair<int,int>P; typedef long long ll; const int MOD=1000000007; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; ll dp[3000][3000]; ll x[3000],v[3000],w[3000]; int main(){ ll n,V,L;cin>>n>>V>>L; rep(i,n){ scanf("%lld%lld%lld",&x[i],&v[i],&w[i]); } x[n]=L; if(V<x[0]){ puts("-1");return 0; } memset(dp,0x3f,sizeof(dp)); dp[0][V-x[0]]=0; rep(i,n)rep(j,V+1){ if(dp[i][j]==INFL)continue; ll cost=x[i+1]-x[i]; if(j>=cost)dp[i+1][j-cost]=min(dp[i+1][j-cost],dp[i][j]); if(int nj=min(V,j+v[i]);nj>=cost)dp[i+1][nj-cost]=min(dp[i+1][nj-cost],dp[i][j]+w[i]); } ll Min=INFL; for(int i=0;i<=V;i++){ Min=min(Min,dp[n][i]); } if(Min==INFL)puts("-1"); else cout<<Min<<endl; }