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 int long long
#define mp make_pair
#define pb push_back
using ll = long long;
using ld = long double;
void solve(int T);
void pre();
const int mxn = 1e5 + 5;
const int SQRT = 500;
const int LOG = 20;
const int inf = 1e18;
const int mod = 1e9 + 7;
const ld eps = 1e-9;
int32_t main(){
pre();
int tt = 1;
cin>>tt;
for(int i = 1;i<=tt;i++)solve(i);
return 0;
}
void pre(){
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
}
int dp[mxn];
void solve(int T){
int n;
cin>>n;
int A[n];
for(int i = 0;i<n;i++)cin>>A[i];
memset(dp, -1, sizeof dp);
bool good[n+1];
for(int i = 0;i<=n;i++)good[i] = true;
for(int i = 0;i<n;i++){
for(int j = mxn;j >= A[i];j--){
dp[j] = max(dp[j], dp[j - A[i]]);
}
dp[A[i]] = i;
int sum = 0;
for(int j = i;j>=0;j--){
sum += A[j];
if(sum % 2 != 0 || dp[sum/2] < j)good[i - j + 1] = false;
}
}
int cnt = 0;
for(int i = 1;i<=n;i++){
if(good[i])cnt++;
}
cout<<cnt<<" ";
for(int i = 1;i<=n;i++){
if(good[i])cout<<i<<" ";
}
cout<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |