#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops","O2")
#define sum(l, r) (pref[(r)] - pref[(l) - 1])
const int maxn = 1e3;
const int maxv = 1e5;
int n;
int v[maxn + 1];
int pref[maxn + 1];
short dp[maxv + 1];
bool ans[maxn + 1];
int ans_cnt;
void solve() {
cin >> n;
for(short i = 1; i <= n; i++) {
ans[i] = true;
cin >> v[i];
pref[i] = pref[i - 1] + v[i];
}
dp[0] = maxn + 1;
for(int j = 1; j <= maxv; j++) {
dp[j] = 0;
}
int s = -1;
for(short i = 1; i <= n; i++) {
for(int j = maxv; j > v[i]; --j) {
dp[j] = max(dp[j], dp[j - v[i]]);
}
dp[v[i]] = i;
for(short k = 1; k <= i; k++) {
s = sum(k, i);
if((s & 1) || (dp[s / 2] < k)) {
ans[i - k + 1] = false;
}
}
}
ans_cnt = 0;
for(short i = 1; i <= n; i++) {
if(ans[i]) {
ans_cnt++;
}
}
cout << ans_cnt << " ";
for(short i = 1; i <= n; i++) {
if(ans[i]) {
cout << i << " ";
}
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while(T--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
508 KB |
Output is correct |
2 |
Correct |
146 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
297 ms |
636 KB |
Output is correct |
2 |
Correct |
503 ms |
512 KB |
Output is correct |
3 |
Correct |
534 ms |
528 KB |
Output is correct |
4 |
Correct |
731 ms |
528 KB |
Output is correct |
5 |
Correct |
1065 ms |
528 KB |
Output is correct |
6 |
Correct |
1356 ms |
636 KB |
Output is correct |
7 |
Correct |
1231 ms |
844 KB |
Output is correct |