This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |