Submission #932213

#TimeUsernameProblemLanguageResultExecution timeMemory
932213XiaoyangSplit the sequence (APIO14_sequence)C++17
0 / 100
49 ms85076 KiB
#include<stdio.h> int n, k, a[100010], sl[100010][210], j; long long d[100010], dd[100010], s[100010]; void get_l(int st, int ed, int left, int right) { int i, q, p; long long m=9e19, x; if(left > right) return; p=(left + right)/2; if(st == ed) { for(i = left; i<=right; ++i) sl[i][j]=st; return; } for(i = st; i <= ed; ++i) { x=d[i] + (s[p] - s[i])*(s[p] - s[i]); if (m > x){ m = x; q = i; } } sl[p][j]=q; get_l(st, q, left, p-1); get_l(q, ed, p + 1, right); return; } void back(int x, int dep){ if (dep > 1) { back(sl[x][dep], dep - 1); printf("%d", sl[x][dep]); } return; } int main() { int i, l; scanf("%d%d", &n, &k); for(i=1; i<=n; ++i) scanf("%d", &a[i]); for(i=1; i<=n; ++i) s[i]=s[i-1]+a[i]; for(i=1; i<=n; ++i) d[i]=s[i]*s[i]; for(j=2; j<=k+1; ++j) { // get_l(j - 1, n-(k + 1 - j), j, n); for(i=j; i<=n; ++i) { l=sl[i][j]; dd[i]=d[l] + (s[i] - s[l])*(s[i] - s[l]); } for(i = j; i <= n; ++i) d[i]=dd[i]; } printf("%lld\n", (s[n] * s[n] - d[n])/2); back(n, k + 1); }

Compilation message (stderr)

sequence.cpp: In function 'void get_l(int, int, int, int)':
sequence.cpp:8:15: warning: overflow in conversion from 'double' to 'long long int' changes value from '9.0e+19' to '9223372036854775807' [-Woverflow]
    8 |   long long m=9e19, x;
      |               ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:39:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   for(i=1; i<=n; ++i) scanf("%d", &a[i]);
      |                       ~~~~~^~~~~~~~~~~~~
sequence.cpp: In function 'void get_l(int, int, int, int)':
sequence.cpp:11:3: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
   11 |   if(st == ed)
      |   ^~
#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...