Submission #1032029

#TimeUsernameProblemLanguageResultExecution timeMemory
1032029tvladm2009Kpart (eJOI21_kpart)C++17
100 / 100
449 ms944 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e3 + 7; const int SUM = 1e5 + 7; int a[N], dp[SUM], pref[N]; bool ok[N]; void solve() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; ok[i] = 1; } for (int i = 0; i <= pref[n] / 2; ++i) { dp[i] = 0; } for (int i = 1; i <= n; ++i) { dp[0] = i; for (int j = pref[n] / 2 - a[i]; j >= 0; --j) { dp[j + a[i]] = max(dp[j + a[i]], dp[j]); } for (int j = 1; j <= i; ++j) { if (dp[(pref[i] - pref[i - j]) / 2] <= i - j || (pref[i] - pref[i - j]) % 2 == 1) { ok[j] = 0; } } } int ans = 0; for (int i = 1; i <= n; ++i) ans += ok[i]; cout << ans << " "; for (int i = 1; i <= n; ++i) { if (ok[i]) cout << i << " "; } cout << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...