Submission #81354

#TimeUsernameProblemLanguageResultExecution timeMemory
81354kimjg1119Split the sequence (APIO14_sequence)C++17
0 / 100
23 ms13664 KiB
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; typedef long long ll; typedef pair<ll,int> pli; typedef struct CHT{ ll la[MAXN], lb[MAXN]; int lz[MAXN]; int stkn=0,pt=1; void insert(ll a, ll b, int z){ while(stkn>pt && (lb[stkn]-b)*(la[stkn]-la[stkn-1])<(a-la[stkn])*(lb[stkn-1]-lb[stkn])) stkn--; la[++stkn]=a; lb[stkn]=b; lz[stkn]=z; } pli query(ll x){ while(pt<stkn && (lb[pt]-lb[pt+1])<(la[pt+1]-la[pt])*x) pt++; return make_pair(la[pt]*x+lb[pt],lz[pt]); } }CHT; CHT c[205]; ll a[MAXN],D[205][MAXN],S[MAXN]; int pre[205][MAXN]; int main(){ int n,k; scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) scanf("%lld",&a[i]), S[i]=S[i-1]+a[i]; for(int i=1;i<=k;i++) c[i].insert(0,0,0); for(int i=1;i<=k;i++){ for(int j=1;j<=n;j++){ pli temp=c[i].query(S[j]); D[i][j]=temp.first; pre[i][j]=temp.second; c[i].insert(S[j],D[i-1][j]-S[j]*S[j],j); } } printf("%lld\n",D[k][n]); int here=n; for(int i=1;i<=k;i++){ printf("%d ",pre[k-i+1][here]); here=pre[k][here]; } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:29:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%lld",&a[i]), S[i]=S[i-1]+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...