Submission #550951

#TimeUsernameProblemLanguageResultExecution timeMemory
550951PherokungSplit the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 #define K 205 #define ll long long typedef pair<ll,ll> pa; struct line{ ll m,c,idx; line(ll m,ll c,int i) : m(m), c(c), idx(i) {} ll dot(ll x){ return m*x + c;} ll inter(line l){ return floor((long double)(c-l.c)/(l.m-m));} }; struct CHT{ deque<line> hull; void add(line l){ if(hull.size() >= 1 && hull.back().m == l.m && hull.back().c == l.c) hull.pop_back(); while(hull.size() >= 2 && l.inter(hull.back()) <= hull.back().inter(hull[hull.size()-2])) hull.pop_back(); hull.push_back(l); } pa query(ll x){ while(hull.size() >= 2 && hull[0].dot(x) <= hull[1].dot(x)) hull.pop_front(); return {hull[0].dot(x), hull[0].idx}; } }; ll n,k,a[N],pre[N],P[K][N],pos, dp[2][N],ans=-9e18; int main(){ scanf("%lld%lld",&n,&k); for(int i=1;i<=n;i++) scanf("%lld",&a[i]), pre[i] = pre[i-1] + a[i]; for(int i=1;i<n;i++) dp[1][i] = 1ll*(pre[n] - pre[i]) * pre[i]; for(int i=2;i<=k;i++){ int now = i%2, prv = now^1; CHT cht; for(int j=i;j<n;j++){ cht.add(line(pre[j-1], 1ll * -pre[j-1] * pre[n] + dp[prv][j-1], j-1)); pa mx = cht.query(pre[j]); long long res = mx.first, idx = mx.second; dp[now][j] = res + 1ll * pre[j] * pre[n] - 1ll * pre[j] * pre[j]; P[i][j] = idx; } } for(int i=k;i<n;i++){ if(dp[k%2][i] > ans){ ans = dp[k%2][i]; pos = i; } } stack<ll> stk; while(k){ stk.push(pos); pos = P[k--][pos]; } printf("%lld\n",ans); while(!stk.empty(){ printf("%lld ",stk.top()); stk.pop(); } }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:58:20: error: expected ')' before '{' token
   58 |  while(!stk.empty(){
      |       ~            ^
      |                    )
sequence.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%lld%lld",&n,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
sequence.cpp:30:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  for(int i=1;i<=n;i++) scanf("%lld",&a[i]), pre[i] = pre[i-1] + a[i];
      |                        ~~~~~^~~~~~~~~~~~~~