Submission #57041

#TimeUsernameProblemLanguageResultExecution timeMemory
57041PlurmSplit the sequence (APIO14_sequence)C++17
71 / 100
2063 ms132096 KiB
#include <cstdio> #include <cstring> #define bad(x,y,z) ((C[y]-C[x])*(M[x]-M[z]) >= (C[z]-C[x])*(M[x]-M[y])) int a[100005]; long long dp[100005]; long long qs[100005]; int par[100005][256]; long long M1[100005]; long long C1[100005]; int idx1[100005]; long long M2[100005]; long long C2[100005]; int idx2[100005]; int prt[100005]; int ptr1,ptr2; int csz1,csz2; int main(){ int n,k; scanf("%d%d",&n,&k); k++; csz1++; for(int i = 1; i <= n; i++){ scanf("%d",a+i); qs[i] = qs[i-1] + (long long)a[i]; dp[i] = -1e16; } for(int j = 1; j <= k; j++){ csz2 = ptr2 = 0; int id; for(int i = j; i <= n; i++){ if(ptr1 >= csz1) ptr1 = csz1-1; while(ptr1 < csz1-1 && M1[ptr1+1]*qs[i] + C1[ptr1+1] > M1[ptr1]*qs[i] + C1[ptr1]) ptr1++; id = ptr1; par[i][j] = idx1[id]; dp[i] = M1[id]*qs[i] + C1[id]; while(csz2 >= 2 && (C2[csz2-1]-C2[csz2-2])*(M2[csz2-2]-qs[i]) >= (dp[i]-qs[i]*qs[i]-C2[csz2-2])*(M2[csz2-2]-M2[csz2-1])) csz2--; M2[csz2] = qs[i]; C2[csz2] = dp[i] - qs[i]*qs[i]; idx2[csz2] = i; csz2++; } memmove(M1,M2,csz2*sizeof(long long)); memmove(C1,C2,csz2*sizeof(long long)); memmove(idx1,idx2,csz2*sizeof(long long)); csz1 = csz2; ptr1 = ptr2; } printf("%lld\n",dp[n]); int x = n; csz1 = 0; for(int j = k; j > 1; j--){ x = par[x][j]; prt[csz1++] = x; } for(int i = 0; i < csz1; i++){ printf("%d ",prt[i]); } }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:19: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:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",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...