#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz(v) (int)v.size()
#define nl "\n"
using namespace std;
const int N = (int)1e3 + 7;
const int MOD = (int)1e9 + 7;
const int M = (int)5e4 + 7;
int n, a[N], dp[M], lst[M];
bool ok[N];
void solve() {
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i];
fill(ok + 1, ok + 1 + n, 1);
fill(lst, lst + M, -1);
for(int i = 1; i <= n; ++i) {
for(int w = M - a[i] - 1; w >= 0; --w) {
if(lst[w] != -1) lst[w + a[i]] = max(lst[w + a[i]], lst[w]);
}
lst[a[i]] = i;
int sum = 0;
for(int j = i; j >= 1; --j) {
sum += a[j];
if(sum & 1) {
ok[i - j + 1] = 0;
} else {
if(lst[sum / 2] < j) ok[i - j + 1] = 0;
}
}
}
vector<int> ans;
for(int i = 1; i <= n; ++i) if(ok[i]) ans.pb(i);
cout << sz(ans) << ' ';
for(auto x : ans) cout << x << ' ';
cout << nl;
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test;
cin >> test;
while(test--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
588 KB |
Output is correct |
2 |
Correct |
110 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
544 KB |
Output is correct |
2 |
Correct |
380 ms |
540 KB |
Output is correct |
3 |
Correct |
380 ms |
548 KB |
Output is correct |
4 |
Correct |
534 ms |
672 KB |
Output is correct |
5 |
Correct |
783 ms |
588 KB |
Output is correct |
6 |
Correct |
995 ms |
604 KB |
Output is correct |
7 |
Correct |
884 ms |
600 KB |
Output is correct |