Submission #615893

#TimeUsernameProblemLanguageResultExecution timeMemory
615893KazamaHoangSplit the sequence (APIO14_sequence)C++14
0 / 100
2076 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; } namespace sub1 { bool used[15]; long long res = 0; vector<int> ans; void back_track(long long cur = 0) { 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 = vt; } 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; back_track(cur + 1ll * pref * (s - pref)); used[j] = 0; pref += a[j]; } } } void solve() { back_track(); cout << res << "\n"; for (auto x : ans) cout << x << " "; } } 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)':
sequence.cpp:24:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |         if (vt.size() == k + 1) {
      |             ~~~~~~~~~~^~~~~~~~
sequence.cpp:32:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         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...