結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2018-12-22 14:24:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,913 bytes |
コンパイル時間 | 748 ms |
コンパイル使用メモリ | 73,756 KB |
実行使用メモリ | 10,272 KB |
最終ジャッジ日時 | 2024-07-08 05:07:57 |
合計ジャッジ時間 | 7,640 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 TLE * 1 -- * 32 |
ソースコード
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <numeric> #define ll long long using namespace std; typedef struct tga{ ll s,t,y,m; } tga; int main(){ ll N,C,V,numCount=0,ansTime=-1; cin>>N>>C>>V; vector<ll> st,yst,mst,ist; vector<tga> v(V); vector<ll> goty(V+1,0),gotm(V+1,0); for(ll i=0;i<V;i++){ cin>>v[i].s; } for(ll i=0;i<V;i++){ cin>>v[i].t; } for(ll i=0;i<V;i++){ cin>>v[i].y; } for(ll i=0;i<V;i++){ cin>>v[i].m; } sort(v.begin(),v.end(), [](const tga& a,const tga& b) {return a.t< b.t;}); st.push_back(N); for(ll i=0;;i++){ if(st[st.size()-1]==v[i].t){ yst.push_back(v[i].y); mst.push_back(v[i].m); if(goty[i]!=0&&gotm[i]!=0&& accumulate(mst.begin(),mst.end(),0)>gotm[i]&& accumulate(yst.begin(),yst.end(),0)>goty[i]){ yst.pop_back(); mst.pop_back(); continue; } gotm[i]=accumulate(mst.begin(),mst.end(),0); goty[i]=accumulate(yst.begin(),yst.end(),0); st.push_back(v[i].s); ist.push_back(i); i=-1; } else if(st[st.size()-1]==1){ if(C>=accumulate(yst.begin(),yst.end(),0)){ if(ansTime==-1){ ansTime=accumulate(mst.begin(),mst.end(),0); } else{ if(ansTime>accumulate(mst.begin(),mst.end(),0)) ansTime=accumulate(mst.begin(),mst.end(),0); } } numCount++; st.pop_back(); i=ist[ist.size()-1]; ist.pop_back(); yst.pop_back(); mst.pop_back(); } else if(v[i].t>st[st.size()-1]){ if(st[st.size()-1]==N) break; st.pop_back(); i=ist[ist.size()-1]; ist.pop_back(); yst.pop_back(); mst.pop_back(); } } printf("%lld",ansTime); }