Submission #197936

#TimeUsernameProblemLanguageResultExecution timeMemory
197936songcSplit the sequence (APIO14_sequence)C++14
0 / 100
83 ms87392 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; int N, K; LL S[101010]; int P[101010][220]; vector<int> ans; struct Line{ LL m, k; int id; }; bool popchk(Line a, Line b, Line c){ return ((double)b.k-c.k)*(b.m-a.m) <= ((double)a.m-b.m)*(c.k-a.k); } struct ConvHull{ vector<Line> V; int p; void push(Line l){ if (!V.empty() && V.back().m == l.m) return; while (V.size()>2 && popchk(V[V.size()-2], V.back(), l)){ V.pop_back(); if (V.size() <= p) p--; } V.push_back(l); } pii read(LL x){ while (p < V.size()-1 && V[p].m*x+V[p].k <= V[p+1].m*x+V[p+1].k) p++; return pii(V[p].m*x+V[p].k, V[p].id); } } CHT[220]; int main(){ scanf("%d %d", &N, &K); K++; for (int i=1; i<=N; i++){ scanf("%lld", &S[i]); S[i] += S[i-1]; } CHT[0].push((Line){0, 0, 0}); for (int i=1; i<=N; i++){ for (int j=1; j<=min(i, K); j++){ LL ret; tie(ret, P[i][j]) = CHT[j-1].read(S[i]); if (i == N && j == K) printf("%lld\n", ret); CHT[j].push((Line){S[i], ret-S[i]*S[i], i}); } } K--; for (int p=P[N][K+1]; K; p=P[p][K], K--) ans.push_back(p); reverse(ans.begin(), ans.end()); for (int x : ans) printf("%d ", x); printf("\n"); return 0; }

Compilation message (stderr)

sequence.cpp: In member function 'void ConvHull::push(Line)':
sequence.cpp:28:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (V.size() <= p) p--;
        ~~~~~~~~~^~~~
sequence.cpp: In member function 'pii ConvHull::read(LL)':
sequence.cpp:34:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (p < V.size()-1 && V[p].m*x+V[p].k <= V[p+1].m*x+V[p+1].k) p++;
          ~~^~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~~
sequence.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &S[i]);
   ~~~~~^~~~~~~~~~~~~~~
#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...