#include <bits/stdc++.h>
using namespace std;
#define maxa 100005
#define maxn 1005
int n,a[maxn],dp[maxa],pre[maxn];
bool check[maxn];
void solve(){
cin >> n;
for(int i=1;i<=n;i++){cin >> a[i];check[i]=true;pre[i]=pre[i-1]+a[i];}
int sum=0;dp[0]=maxn;
for(int j=1;j<=pre[n]/2;j++) dp[j]=0;
for(int i=1;i<=n;i++){
sum+=a[i];
for(int j=min(sum,pre[n]/2);j>=a[i];j--) dp[j]=max(dp[j],min(dp[j-a[i]],i));
for(int j=i;j>=1;j--){
int total=pre[i]-pre[j-1];
if(dp[total/2]<j || total%2==1) check[i-j+1]=false;
}
}
int num=0;
for(int i=1;i<=n;i++){
if(check[i]) num++;
}
cout << num << ' ';
for(int i=1;i<=n;i++){
if(check[i]) cout << i << ' ';
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;cin >> t;
while(t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
360 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
400 KB |
Output is correct |
2 |
Correct |
89 ms |
432 KB |
Output is correct |
3 |
Correct |
101 ms |
448 KB |
Output is correct |
4 |
Correct |
189 ms |
484 KB |
Output is correct |
5 |
Correct |
414 ms |
576 KB |
Output is correct |
6 |
Correct |
585 ms |
688 KB |
Output is correct |
7 |
Correct |
537 ms |
716 KB |
Output is correct |