Submission #660357

# Submission time Handle Problem Language Result Execution time Memory
660357 2022-11-21T17:42:57 Z leroycut Split the sequence (APIO14_sequence) C++17
0 / 100
72 ms 131072 KB
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
 
const int N = 1e5 + 3;
const ll INF = 2e12 + 3;

int n, k;
ll dp[N][203], p[N], ppm[N];
 
ld cross(int i, int j, int c){
    ld rb = (dp[j][c - 1] - p[j] * p[j]) - (dp[i][c - 1] - p[i] * p[i]);
    ld rk = p[i] - p[j];
    return rb / rk;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n >> k;
    for(int i = 1; i <= n; ++i){
        ll a;
        cin >> a;
        p[i] = p[i - 1] + a;
        ppm[i] = ppm[i - 1] + a * p[i - 1];
    }


    for(int j = 1; j <= k; ++j){
        deque<int> q;
        for(int i = 1; i < j + 1; ++i){
            q.push_back(i);
            dp[i][j] = ppm[i];
        }
        for(int i = j + 1; i <= n; ++i){
            while(q.size() > 1 && cross(q[0], q[1], j) <= p[i]) q.pop_front();
            int t = q.front();
            dp[i][j] = dp[t][j - 1] + p[t] * (p[i] - p[t]);
            // cout << dp[i][j] << " ";
            // for(int t = 1; t < i; ++t){
            //     dp[i][j] = max(dp[i][j], dp[t][j - 1] + p[t] * (p[i] - p[t]));
            // }
            while(q.size() > 1 && cross(q.back(), i, j) >= cross(q[q.size() - 2], q.back(), j)) q.pop_back();
            q.push_back(i);
        }
        // cout << "\n";
    }

    cout << dp[n][k] << "\n";
    int poi = n - 1, end = n, cnt = k - 1;
    for(; poi >= 1 && cnt >= 0; --poi){
        if(dp[poi][cnt] + p[poi] * (p[end] - p[poi]) == dp[end][cnt + 1]){
            cout << poi << " ";
            end = poi;
            cnt--;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB contestant found the optimal answer: 108 == 108
2 Incorrect 1 ms 340 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 340 KB contestant didn't find the optimal answer: 252296 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB contestant didn't find the optimal answer: 201746 < 610590000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1876 KB contestant didn't find the optimal answer: 96072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 16340 KB contestant didn't find the optimal answer: 1187838 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -