Submission #331028

#TimeUsernameProblemLanguageResultExecution timeMemory
331028leinad2Split the sequence (APIO14_sequence)C++14
100 / 100
868 ms92764 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n, i, j, k, t, a, A[100010], dp[100010][2], chk[100010]; struct line { ll a, b, index; }; vector<line>V; double cross(const line &p, const line &q) { return (double)(q.b-p.b)/(p.a-q.a); } void push(line x) { if(V.size()&&V.back().a==x.a) { if(V.back().b<x.b)V.back().b=x.b; return; } while(V.size()>=2) { if(cross(V.back(), V[V.size()-2])>cross(V.back(), x))V.pop_back(); else break; } V.push_back(x); } pair<ll, ll>query(ll x) { if(V.size()<=a)a=V.size()-1; else while(a+1<V.size()&&cross(V[a+1], V[a])<=x)a++; return {V[a].a*x+V[a].b, V[a].index}; } int backtrack[100010][210]; int main() { for(scanf("%lld %lld", &n, &k);i++<n;) { scanf("%lld", &A[i]); A[i]+=A[i-1]; } for(j=0;j++<k;) { for(a=i=0;i++<n;) { push({A[i], dp[i][0]-A[i]*A[i], i}); pair<ll, ll>p=query(A[i]); dp[i][1]=p.first; backtrack[i][j]=p.second; dp[i][0]=dp[i][1]; } V.clear(); } printf("%lld\n", dp[n][1]); i=n; j=k; vector<int>ans; while(j>0) { i=backtrack[i][j]; j--; ans.push_back(i); } set<int>s; for(i=0;++i<n;)s.insert(i); while(ans.size()) { if(ans.back()>=n) { ans.back()=*s.begin(); } printf("%d ", ans.back()); chk[ans.back()]=1; s.erase(ans.back()); ans.pop_back(); } }

Compilation message (stderr)

sequence.cpp: In function 'std::pair<long long int, long long int> query(ll)':
sequence.cpp:30:16: warning: comparison of integer expressions of different signedness: 'std::vector<line>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   30 |     if(V.size()<=a)a=V.size()-1;
      |        ~~~~~~~~^~~
sequence.cpp:31:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     else while(a+1<V.size()&&cross(V[a+1], V[a])<=x)a++;
      |                ~~~^~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     for(scanf("%lld %lld", &n, &k);i++<n;)
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   39 |         scanf("%lld", &A[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...