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 ll long long
#define ff first
#define ss second
const int N = 3e5+5;
int T, n;
int main(){
// freopen("file.in", "r", stdin);
cin >> T;
while(T--){
cin >> n;
vector <int> a(n+1);
int s = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
s += a[i];
}
vector <int> vis(n+1,0);
for(int i = 1; i <= n; i++){
vector <bool> dp(s+1,0);
dp[0] = 1;
int s1 = 0;
for(int j = i; j <= n; j++){
s1 += a[j];
for(int k = s-a[j]; k >= 0; k--){
if(dp[k] == 1) dp[k + a[j]] = 1;
}
if(dp[s1/2] == 1 and s1 % 2 == 0) vis[(j-i+1)]++;
}
s -= a[i];
}
int cnt = 0;
vector <int> v;
for(int i = 1; i <= n; i++){
if(vis[i] == n-i+1){
cnt++;
v.push_back(i);
}
}
cout << cnt << ' ';
for(auto i : v){
cout << i << " ";
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |