Submission #848733

# Submission time Handle Problem Language Result Execution time Memory
848733 2023-09-13T12:05:11 Z lbadea1000 Split the sequence (APIO14_sequence) C++17
0 / 100
12 ms 1624 KB
#include <bits/stdc++.h>
using namespace std;

const int NMAX = 1e5;

int v[NMAX], sp[NMAX];

vector<int> split_points;

int sum(int l, int r) {
    if(l == 0) return sp[r];
    return sp[r] - sp[l - 1];
}

int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> v[i];
    sp[0] = v[0];
    for(int i = 1; i < n; i++)
        sp[i] = sp[i - 1] + v[i];
    
    long long ans = 0;
    int kk = k;
    while(kk--) {
        int first = -1, end;
        int ind = 0;
        long long maxx = 0, pozmax = 0;
        if(split_points.size() == 0)
            end = n - 1;
        else end = split_points[0];
        for(int i = 0; i < n; i++) {
            if(ind < split_points.size() && i == split_points[ind]) {
                first = split_points[ind];
                ind++;
                if(ind == split_points.size())
                    end = n - 1;
                else end = split_points[ind];
            } else {
                // (first, i] cu [i + 1, end]
                //cout << i << ' ' << first << ' ' << end << endl;
                long long val = 1LL * sum(first + 1, i) * sum(i + 1, end);
                if(val >= maxx) {
                    maxx = val;
                    pozmax = i;
                }
            }
        }
        //cout << maxx << ' ' << pozmax << endl;
        ans += maxx;
        split_points.push_back(pozmax);
        sort(split_points.begin(), split_points.end());
    }
    cout << ans << endl;
    //cout << ans << ' ' << k << endl;
    for(int i = 0; i < k; i++)
        cout << split_points[i] + 1 << ' ';
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             if(ind < split_points.size() && i == split_points[ind]) {
      |                ~~~~^~~~~~~~~~~~~~~~~~~~~
sequence.cpp:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                 if(ind == split_points.size())
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB contestant found the optimal answer: 108 == 108
2 Incorrect 0 ms 344 KB contestant didn't find the optimal answer: 951 < 999
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB contestant didn't find the optimal answer: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 344 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 2 ms 344 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 0 ms 344 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 1 ms 344 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 1 ms 344 KB Integer 200 violates the range [1, 199]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 488 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1368 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Incorrect 12 ms 1624 KB contestant didn't find the optimal answer: 19874432171 < 19874432173
3 Halted 0 ms 0 KB -