Submission #552524

#TimeUsernameProblemLanguageResultExecution timeMemory
552524tht2005Split the sequence (APIO14_sequence)C++17
39 / 100
2077 ms3488 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100005; const int K = 202; int n, kk, s[N], trc[K][N]; LL f[N], g[N]; int main() { scanf("%d %d", &n, &kk); for(int i = 1; i <= n; ++i) { int a; scanf("%d", &a); s[i] = s[i - 1] + a; } memset(f, 0, sizeof(f)); for(int t = 1; t <= kk; ++t) { memcpy(g, f, sizeof(g)); memset(f, 0, sizeof(f)); for(int i = t + 1; i <= n; ++i) { for(int j = i - 1; j >= t; --j) { LL _ = g[j] + (LL)s[j] * (s[i] - s[j]); if(f[i] < _) { f[i] = _; trc[t][i] = j; } } } } printf("%lld\n", f[n]); for(int i = n; (i = trc[kk--][i]); ) { printf("%d ", i); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
sequence.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
#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...