Submission #113079

# Submission time Handle Problem Language Result Execution time Memory
113079 2019-05-23T14:07:43 Z dolphingarlic Split the sequence (APIO14_sequence) C++14
0 / 100
74 ms 17144 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int n, k;
pair<int, int> dp[201][100001];
int pref[100001]{0};

bool case1(int x, int y, int i, int indx) {
    return (dp[indx][y].first - dp[indx][x].first >=
            (pref[y] - pref[x]) * (pref[n] - pref[i]));
}

bool case2(int x, int y, int i, int indx) {
    return ((dp[indx][y].first - dp[indx][x].first) * (pref[i] - pref[y]) <=
            (dp[indx][i].first - dp[indx][y].first) * (pref[y] - pref[x]));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    FOR(i, 1, n + 1) {
        int x;
        cin >> x;
        pref[i] = pref[i - 1] + x;
    }

    fill(dp[0], dp[0] + n + 1, make_pair(0, 0));
    FOR(i, 1, k + 1) {
        deque<int> q;
        q.push_back(0);
        dp[i][0] = {0, 0};
        FOR(j, 1, n + 1) {
            while (q.size() > 1 && case1(q[0], q[1], j, i - 1)) q.pop_front();

            int x = q[0];
            dp[i][j] = {dp[i - 1][x].first + (pref[j] - pref[x]) * (pref[n] - pref[j]), x};

            while (q.size() > 1 && case2(q[q.size() - 2], q[q.size() - 1], j, i - 1)) q.pop_back();
            q.push_back(j);
        }
    }

    int mx = -1, indx = -1;
    FOR(i, 1, n + 1) {
        if (dp[k][i].first > mx) mx = dp[k][i].first, indx = i;
    }
    cout << mx << '\n';
    FOR(i, 0, k) {
        cout << indx << ' ';
        indx = dp[k - i][indx].second;
    }
    cout << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 404 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 384 KB contestant found the optimal answer: 0 == 0
4 Correct 2 ms 356 KB contestant found the optimal answer: 1542524 == 1542524
5 Incorrect 2 ms 356 KB Integer 0 violates the range [1, 9]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 1 ms 384 KB contestant found the optimal answer: 302460000 == 302460000
3 Incorrect 2 ms 640 KB Integer 0 violates the range [1, 49]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 384 KB contestant found the optimal answer: 311760000 == 311760000
3 Incorrect 3 ms 1792 KB Integer 0 violates the range [1, 199]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 356 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 2 ms 384 KB contestant found the optimal answer: 140412195 == 140412195
3 Incorrect 9 ms 2944 KB Integer 0 violates the range [1, 999]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 740 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 3 ms 768 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Incorrect 74 ms 17144 KB Integer 0 violates the range [1, 9999]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 4164 KB declared answer doesn't correspond to the split scheme: declared = 2147474611, real = 15032376499
2 Halted 0 ms 0 KB -