結果
問題 |
No.1 道のショートカット
|
ユーザー |
|
提出日時 | 2021-08-23 15:33:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 941 bytes |
コンパイル時間 | 1,737 ms |
コンパイル使用メモリ | 175,564 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 18:03:28 |
合計ジャッジ時間 | 3,387 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:36:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 36 | for(auto [to,w,time]:r[i]){ | ^
ソースコード
#include"bits/stdc++.h" using namespace std; typedef long long ll; template <class T> void chmin(T &a,T b){ if(a>b)a=b; } ll dp[51][301]; const long long INF=1LL<<60; int main(){ ll n,c,v; cin>>n>>c>>v; vector<ll>s(v),t(v),m(v),y(v); vector<vector<tuple<ll,ll,ll>>>r(n+1); for(ll i=0;i<v;i++)cin>>s[i]; for(ll i=0;i<v;i++)cin>>t[i]; for(ll i=0;i<v;i++)cin>>y[i]; for(ll i=0;i<v;i++)cin>>m[i]; for(ll i=0;i<v;i++){ r[s[i]-1].push_back({t[i]-1,y[i],m[i]}); } for(ll i=1;i<51;i++){ for(ll j=0;j<301;j++){ dp[i][j]=INF; } } for(ll i=0;i<n;i++){ for(ll j=0;j<=c;j++){ for(auto [to,w,time]:r[i]){ if(j+w<=c){ chmin(dp[to][j+w],dp[i][j]+time); } } } } if(dp[n-1][c]==INF){ cout<<-1<<endl; }else{ cout<<dp[n-1][c]<<endl; } }