Submission #615898

#TimeUsernameProblemLanguageResultExecution timeMemory
615898KazamaHoangSplit the sequence (APIO14_sequence)C++14
0 / 100
2082 ms131072 KiB
#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 = 0;
    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)

sequence.cpp: In function 'void sub1::back_track(long long int, std::vector<int>)':
sequence.cpp:30:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |         if (vt.size() == k + 1) {
      |             ~~~~~~~~~~^~~~~~~~
sequence.cpp:38:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for (int i = 0; i + 1 < vt.size(); ++ i) {
      |                         ~~~~~~^~~~~~~~~~~
sequence.cpp: In function 'int what_subtask_is_the_input()':
sequence.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
    9 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...