#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 5;
const int inf = 1e9 + 7;
int a[maxN];
int pfs[maxN];
void solve () {
int n;
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
pfs[i] = pfs[i - 1] + a[i];
}
int lim = pfs[n];
vector <int> dp (lim + 1, 0LL); // vi tri xa nhat ma tao duoc tong i bat dau
vector <bool> ok (lim + 1, true);
for (int i = 1; i <= n; i ++) {
for (int s = lim; s >= a[i]; s --) {
dp[s] = max (dp[s], dp[s - a[i]]);
}
dp[a[i]] = max (dp[a[i]], i);
for (int j = 1; j <= i; j ++) {
if ((pfs[i] - pfs[j - 1]) % 2) {
ok[i - j + 1] = false;
}
else if (dp[(pfs[i] - pfs[j - 1]) / 2] < j) {
//cout << dp[(pfs[i] - pfs[j - 1]) / 2] << ' ' << i << ' ' << j << '\n';
ok[i - j + 1] = false;
}
}
}
vector <int> res;
for (int i = 1; i <= n; i ++) {
if (ok[i]) {
res.push_back (i);
}
}
cout << res.size () << ' ';
for (auto it : res) {
cout << it << ' ';
}
cout << '\n';
}
signed main () {
ios_base :: sync_with_stdio (0);
cin.tie (0);
int testCase = 1;
cin >> testCase;
while (testCase --) {
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... |