Submission #524585

#TimeUsernameProblemLanguageResultExecution timeMemory
524585NursikKpart (eJOI21_kpart)C++14
100 / 100
939 ms912 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define ld long double #define f first #define s second #define mp make_pair const ll maxn = 1e5 + 1, maxm = 5e4 + 1, maxk = 61; const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353; const ll pa = 31; using namespace std; int t, n; int a[maxn], pref[maxn], pos[maxn]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> t; while (t--){ cin >> n; vector<int> ans; for (int i = 1; i <= n; ++i){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; ans.pb(i); } for (int i = 0; i <= pref[n]; ++i){ pos[i] = -1; } pos[0] = 0; for (int i = 1; i <= n; ++i){ for (int j = maxm - 1; j >= 0; --j){ if (pos[j] != -1 && j + a[i] <= maxm - 1){ pos[j + a[i]] = max(pos[j + a[i]], pos[j]); } } pos[a[i]] = i; vector<int> next; for (auto it : ans){ if (it > i){ next.pb(it); continue; } ll sum = pref[i] - pref[i - it]; if (sum % 2 == 0 && pos[sum / 2] >= i - it + 1){ next.pb(it); } } ans = next; } cout << ans.size() << " "; for (auto it : ans){ cout << it << " "; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...