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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |