Submission #552508

#TimeUsernameProblemLanguageResultExecution timeMemory
552508tht2005Split the sequence (APIO14_sequence)C++17
0 / 100
2088 ms79728 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int INF = numeric_limits<int>::max() / 2;

const int N = 100005;
const int K = 202;
int n, kk;
int s[N], f[K][N];

int main() {
    scanf("%d %d", &n, &kk);
    ++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 = 2; t <= kk; ++t) {
        for(int i = t; i <= n; ++i) {
            for(int j = i - 1; j >= t - 1; --j) {
                f[t][i] = max(f[t][i], f[t - 1][j] + s[j] * (s[i] - s[j]));
            }
        }
    }
    printf("%lld\n", f[kk][n]);
    for(int i, j = n; kk --> 1; ) {
        for(i = j; i--; ) {
            if(f[kk + 1][j] == f[kk][i] + s[i] * (s[j] - s[i])) {
                printf("%d ", i);
                j = i;
                break;
            }
        }
    }
    return 0;
}

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:29:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
   29 |     printf("%lld\n", f[kk][n]);
      |             ~~~^     ~~~~~~~~
      |                |            |
      |                |            int
      |                long long int
      |             %d
sequence.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d", &n, &kk);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
sequence.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         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...