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>
#define ent '\n'
#define fi first
#define se second
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const int inf = (int)(1e9 + 7);
const ll INF = (ll)(2e18 + 7);
const ld eps = (ld)(1e-12);
const int dx[] = { -1,0,1,0,1,1,-1,-1 }, dy[] = { 0,1,0,-1,1,-1,1,-1 };
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
int n,a[N],dp[N][50010],cnt[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
cnt[i]=0;
}
for(int i=0;i<=n;i++){
for(int j=0;j<=5e4;j++){
dp[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<=5e4;j++){
dp[i][j]=max(dp[i][j],dp[i-1][j]);
if(j+a[i]<=5e4){
if(!j){
dp[i][j+a[i]]=max(dp[i][j+a[i]],i);
}
else{
dp[i][j+a[i]]=max(dp[i][j+a[i]],dp[i-1][j]);
}
}
}
}
for(int i=1;i<=n;i++){
ll sum=0;
for(int j=i;j<=n;j++){
sum+=a[j];
if(sum&1) continue;
if(i<=dp[j][sum>>1]){
cnt[j-i+1]++;
}
}
}
vector<int> ans;
for(int i=1;i<=n;i++){
if(cnt[i]==n-i+1){
ans.pb(i);
}
}
cout<<sz(ans)<<' ';
for(auto it:ans){
cout<<it<<' ';
}
cout<<ent;
return;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
//freopen(".in", "r", stdin);
//freopen(".out","w",stdout);
int ttt=1;
cin>>ttt;
for(int i=1;i<=ttt;i++){
//cout<<"NEWCASE"<<ent;
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |