제출 #842632

#제출 시각아이디문제언어결과실행 시간메모리
842632PacybwoahBigger segments (IZhO19_segments)C++17
0 / 100
1 ms348 KiB
#include<iostream> #include<vector> #include<utility> #define ll long long using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<ll> vec(n),pre(n+1); for(int i=0;i<n;i++) cin>>vec[i]; for(int i=1;i<=n;i++) pre[i]=pre[i-1]+vec[i-1]; vector<pair<ll,int> > dp(n); dp[0]=make_pair(vec[0],1); int l=-1; for(int i=1;i<n;i++){ while(l<i-1&&dp[l+1].first<=pre[i+1]-pre[l+2]) l++; if(l==-1) dp[i]=make_pair(pre[i+1],1); else dp[i]=make_pair(pre[i+1]-pre[l+1],dp[l].second+1); //cout<<l<<" "<<dp[i].first<<" "<<dp[i].second<<"\n"; } cout<<dp[n-1].second; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...