Submission #552853

#TimeUsernameProblemLanguageResultExecution timeMemory
552853mars4Split the sequence (APIO14_sequence)C++17
100 / 100
1097 ms82160 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define i128 __int128_t #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- const ll N=100'000; const ll K=200; ll a[N]; ll pre[N+1]; int v[K][N]; vector<ll> dp1(N); vector<ll> dp2(N); ll sz; ll sum(ll l,ll r) { return pre[r+1]-pre[l]; } void calc(ll l,ll r,ll optL,ll optR,ll level) { if(l>r or l==sz-1) { return; } ll mid=(l+r)>>1; pair<ll,ll> best={LLONG_MIN,-1}; for(ll i=optL;i<=min(mid,optR);i++) { ll ex=sum(i,mid)*sum(mid+1,sz-1); ll val=(i?dp1[i-1]:0)+ex; if(val>best.ff) { best={val,i}; } } dp2[mid]=best.ff; ll opt=best.ss; v[level][mid]=opt; calc(l,mid-1,optL,opt,level); calc(mid+1,r,opt,optR,level); } int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; cin>>n>>k; sz=n; forn(i,0,n) { cin>>a[i]; pre[i+1]=pre[i]+a[i]; } forn(i,0,k) { calc(i,n-1,i,n-1,i); dp1.swap(dp2); } pair<ll,ll> mval={-1,-1}; forn(i,0,n-1) { mval=max(mval,{dp1[i],i}); } vector<ll> ans; ll ind=mval.ss; forb(i,k-1,0) { ans.push_back(ind); ind=v[i][ind]-1; } reverse(all(ans)); cout<<mval.ff<<"\n"; for(ll i:ans) { cout<<i+1<<" "; } nl; cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:87:5: warning: unused variable 'z' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
sequence.cpp:87:9: warning: unused variable 'm' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |         ^
sequence.cpp:87:11: warning: unused variable 't' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
sequence.cpp:87:15: warning: unused variable 'i' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
sequence.cpp:87:17: warning: unused variable 'j' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                 ^
sequence.cpp:87:19: warning: unused variable 'l' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                   ^
sequence.cpp:87:21: warning: unused variable 'd' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                     ^
sequence.cpp:87:23: warning: unused variable 'h' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                       ^
sequence.cpp:87:25: warning: unused variable 'r' [-Wunused-variable]
   87 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                         ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...