| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 615949 | KazamaHoang | Split the sequence (APIO14_sequence) | C++14 | 2070 ms | 131072 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
 
int n, k, a[100005];
 
int what_subtask_is_the_input() {
    if (n <= 10) return 1;
 
}
 
template <typename T>
void println(vector<T>& a) {
    for (auto x : a) cout << x << " ";
    cout << "\n";
}
 
namespace sub1 {
 
    bool used[15];
    long long res = -1;
    vector<int> ans;
 
    void back_track(long long cur = 0, vector<int> order = {}) {
        vector<int> vt = {1};
        for (int i = 2; i <= n; ++ i) {
            if (used[i]) {
                vt.push_back(i);
            }
        }
        if (vt.size() == k + 1) {
            if (res < cur) {
                res = cur;
                ans = order;
            }
            return;
        }
        vt.push_back(n + 1);
        for (int i = 0; i + 1 < vt.size(); ++ i) {
            int s = 0;
            for (int j = vt[i]; j < vt[i + 1]; ++ j) {
                s += a[j];
            }
            int pref = a[vt[i]];
            for (int j = vt[i] + 1; j < vt[i + 1]; ++ j) {
                used[j] = 1;
                order.push_back(j - 1);
                back_track(cur + 1ll * pref * (s - pref), order);
                order.pop_back();
                used[j] = 0;
                pref += a[j];
            }
        }
    }
 
    void solve() {
        back_track();
        cout << res << "\n";
        println(ans);
    }
}
 
int main() {
    cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
    freopen("main.inp", "r", stdin);
    freopen("main.out", "w", stdout);
#endif // LOCAL
    cin >> n >> k;
    for (int i = 1; i <= n; ++ i) {
        cin >> a[i];
    }
    int sub = what_subtask_is_the_input();
    if (sub == 1) sub1::solve();
    return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
