Submission #684536

# Submission time Handle Problem Language Result Execution time Memory
684536 2023-01-21T14:19:28 Z phoenix Split the sequence (APIO14_sequence) C++17
0 / 100
27 ms 2388 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 1e6;

ll value[N], pref[N];
int n, k;
vector<pair<int, int>> st;
ll res = 0;

vector<int> res_v;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> value[i];
        pref[i] = pref[i - 1] + value[i];
    }
    st.push_back({1, n});
    for(int iter = 1; iter <= k; iter++) {
        ll mx = -1, p_i = 0, inx = 0;

        for(int p = 0; p < (int)st.size(); p++) {
            int l = st[p].first, r = st[p].second; 
            for(int i = l; i < r; i++) {
                if((pref[i] - pref[l - 1]) * (pref[r] - pref[i]) > mx) {
                    mx = (pref[i] - pref[l - 1]) * (pref[r] - pref[i]);
                    p_i = p;
                    inx = i;
                }
            }
        }
        res += mx;
        res_v.push_back(inx);
        st.push_back({inx + 1, st[p_i].second});
        st[p_i].second = inx;
    }
    cout << res << '\n';
    for(int c : res_v) 
        cout << c << ' ';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB contestant found the optimal answer: 108 == 108
2 Incorrect 1 ms 212 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: 1093726 < 1093956
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 1 ms 324 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 1 ms 324 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 1 ms 328 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Incorrect 1 ms 340 KB contestant didn't find the optimal answer: 1019625813 < 1019625819
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB contestant didn't find the optimal answer: 21419072 < 21503404
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB contestant didn't find the optimal answer: 1794250000 < 1818678304
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2048 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 7 ms 2004 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Incorrect 27 ms 2388 KB contestant didn't find the optimal answer: 497009314607795353 < 497313449256899208
4 Halted 0 ms 0 KB -