#include<iostream>
#include<vector>
int cyc[100001];
int main(){
int n,a;
std::cin>>n;
long long sum=0;
std::vector<int> wart;
for(int i=0;i<n;i++){
std::cin>>a;
wart.emplace_back(a);
sum+=a;
}
for(int i=n;i>=1;i--){
if(sum%i==0){
//std::cout<<"test "<<i<<std::endl;
cyc[0]=wart[0];
bool fail=false;
for(int j=1;j<i;j++){
cyc[j]=wart[j]-wart[j-1];
if(cyc[j]<0){
fail=true;
break;
}
}
if(fail)
continue;
for(int j=i;j<n;j++){
cyc[j%i]=wart[j]-wart[j-1]+cyc[j%i];
if(cyc[j%i]<0){
fail=true;
break;
}
//std::cout<<"cyp "<<j%i<<" "<<cyc[j%i]<<std::endl;
}
cyc[n%i]=0;
for(int j=0;j<i;j++){
//std::cout<<"cy "<<j<<" "<<cyc[j]<<std::endl;
if(cyc[j]>0){
fail=true;
break;
}
}
if(!fail){
std::cout<<i<<std::endl;
return 0;
}
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include<iostream> #include<vector> int cyc[100001]; int main(){ int n,a; std::cin>>n; long long sum=0; std::vector<int> wart; for(int i=0;i<n;i++){ std::cin>>a; wart.emplace_back(a); sum+=a; } for(int i=n;i>=1;i--){ if(sum%i==0){ //std::cout<<"test "<<i<<std::endl; cyc[0]=wart[0]; bool fail=false; for(int j=1;j<i;j++){ cyc[j]=wart[j]-wart[j-1]; if(cyc[j]<0){ fail=true; break; } } if(fail) continue; for(int j=i;j<n;j++){ cyc[j%i]=wart[j]-wart[j-1]+cyc[j%i]; if(cyc[j%i]<0){ fail=true; break; } //std::cout<<"cyp "<<j%i<<" "<<cyc[j%i]<<std::endl; } cyc[n%i]=0; for(int j=0;j<i;j++){ //std::cout<<"cy "<<j<<" "<<cyc[j]<<std::endl; if(cyc[j]>0){ fail=true; break; } } if(!fail){ std::cout<<i<<std::endl; return 0; } } } } |
English