제출 #482209

#제출 시각아이디문제언어결과실행 시간메모리
482209luka1234Bigger segments (IZhO19_segments)C++14
27 / 100
1584 ms153268 KiB
#include<bits/stdc++.h> #define ll long long #define ff first #define ss second using namespace std; int a[3001]; ll p[3001]; set<pair<ll,ll> > s[3001]; ll d[3001][3001]; int n; int main(){ cin>>n; for(int k=1;k<=n;k++){ cin>>a[k]; p[k]=p[k-1]+a[k]; } d[0][0]=0; s[0].insert({0,0}); set<pair<ll,ll> >::iterator it; for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ it=s[j-1].lower_bound({p[i]+1,0}); if(it==s[j-1].begin()){ d[i][j]=1e18; continue; } it--; int ind=(*it).ss; d[i][j]=p[i]-p[ind]; ll v=d[i][j]+p[i]; while(!s[j].empty()&&(*s[j].rbegin()).ff>=v){ s[j].erase(*s[j].rbegin()); } s[j].insert({v,i}); } } for(int j=n;j>=1;j--){ if(d[n][j]!=1e18){ cout<<j; return 0; } } return 0; }
#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...