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;
int sum(int a[],int x, int y){
int s = 0;
for(int i=x;i<y;i++) s+=a[i];
return s;
}
bool podeli(int a[], int x, int y){
int b[y-x+5];
for(int i=x;i<y;i++) b[i]=a[i];
sort(b+x,b+y);
int s = sum(b,x,y);
if(s%2==1) return false;
int l = x;
int r = x+1;
while(r>l){
if(sum(b,l,r)==s/2) return true;
else if(sum(b,l,r)>s/2) l++;
else if(sum(b,l,r)<s/2) r++;
}
return false;
}
int main(){
int t;
cin>>t;
for(int e = 0; e<t;e++){
int n;
cin>>n;
int a[n];
int br[n+1];
for(int i=0;i<n;i++){
cin>>a[i];
br[i] = 0;
}
br[n] = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n-i;j++){
if(podeli(a,j,j+i)){
br[i]++;
}
}
}
int rez = 0;
for(int i=1;i<=n;i++){
if(br[i]==n-i+1){
rez++;
}
}
cout<<rez<<" ";
for(int i=1;i<=n;i++) {
if(br[i]==n-i+1) 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... |