#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define el '\n'
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll tt; cin >> tt;
while (tt--) {
ll n; cin >> n;
vector <ll> a(n + 1), pr(n + 1, 0);
for (ll i = 1; i <= n; i++) {
cin >> a[i];
pr[i] = pr[i - 1] + a[i];
}
vector <vector<ll>> dp(n + 1, vector <ll> (5e4 + 1, 0));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= 5e4; j++) {
dp[i][j] = dp[i - 1][j];
if (j == a[i])
dp[i][j] = max(i, dp[i][j]);
if (j - a[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]]);
}
}
vector <ll> ans;
for (ll k = 2; k <= n; k++) {
bool ok = 1;
for (ll i = k; i <= n; i++) {
if ((pr[i] - pr[i - k]) & 1 || dp[i][(pr[i] - pr[i - k]) / 2] < i - k + 1) {
ok = 0;
break ;
}
}
if (ok)
ans.pb(k);
}
cout << ans.size() << ' ';
for (ll v : ans)
cout << v << ' ';
cout << el;
}
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... |