#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(v) (int)(v).size()
using namespace std;
const int MXn = 100005;
int n, a[1003], prf[1003];
int dp[MXn];
bool ok[1003];
long long tot = 0;
void solve(void) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
prf[i] = prf[i - 1] + a[i];
}
memset(dp, -1, sizeof dp);
memset(ok, true, sizeof ok);
int cur = 0;
for (int i = 1; i <= n; i++) {
tot += cur;
for (int s = cur; s > 0; s--) {
dp[s + a[i]] = max(dp[s + a[i]], dp[s]);
}
dp[a[i]] = i;
cur += a[i];
for (int j = 1; j <= i; j++) {
if ((prf[i] - prf[j - 1]) % 2 || dp[(prf[i] - prf[j - 1]) / 2] < j) {
ok[i - j + 1] = false;
}
}
}
vector<int> K;
for (int len = 1; len <= n; len++) if (ok[len]) {
K.emplace_back(len);
}
cout << sz(K) << ' ';
for (int len: K) cout << len << ' ';
cout << '\n';
}
signed main(void) {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int T; cin >> T; while (T--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Correct |
7 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
856 KB |
Output is correct |
2 |
Correct |
82 ms |
860 KB |
Output is correct |
3 |
Correct |
80 ms |
860 KB |
Output is correct |
4 |
Correct |
144 ms |
856 KB |
Output is correct |
5 |
Correct |
363 ms |
848 KB |
Output is correct |
6 |
Correct |
460 ms |
856 KB |
Output is correct |
7 |
Correct |
441 ms |
852 KB |
Output is correct |