#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define vec vector
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
void slv(){
int n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
vi d;
rep(i,n){
d.pb(a[i]-(!i?0:a[i-1]));
}
d.pb(-a.back());
n=sz(d);
int frst=n;
rep(i,n){
if(d[i]<0){
frst=i;
break;
}
}
// print(frst,n);
int ans=1;
for(int k=n-1;k>=2;k--){
if(k-1>=frst){
continue;
}
bool fnd=0;
for(int r=0;r<k;r++){
int now=0;
for(int i=r;i<n;i+=k){
now+=d[i];
if(now<0){
fnd=1;
break;
}
}
// print(now,r);
if(now!=0){
fnd=1;
break;
}
}
if(!fnd){
ans=k;
break;
}
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
int t;
t=1;
// cin>>t;
rep(cs,t){
slv();
}
}
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <bits/stdc++.h> #define int ll using namespace std; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define rng(i,c,n) for(int i=c;i<n;i++) #define fi first #define se second #define vec vector #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; void print(){cout<<'\n';} template<class h,class...t> void print(const h&v,const t&...u){cout<<v<<' ',print(u...);} void slv(){ int n; cin>>n; vi a(n); rep(i,n){ cin>>a[i]; } vi d; rep(i,n){ d.pb(a[i]-(!i?0:a[i-1])); } d.pb(-a.back()); n=sz(d); int frst=n; rep(i,n){ if(d[i]<0){ frst=i; break; } } // print(frst,n); int ans=1; for(int k=n-1;k>=2;k--){ if(k-1>=frst){ continue; } bool fnd=0; for(int r=0;r<k;r++){ int now=0; for(int i=r;i<n;i+=k){ now+=d[i]; if(now<0){ fnd=1; break; } } // print(now,r); if(now!=0){ fnd=1; break; } } if(!fnd){ ans=k; break; } } cout<<ans<<"\n"; } signed main(){ ios::sync_with_stdio(0),cin.tie(0); int t; t=1; // cin>>t; rep(cs,t){ slv(); } } |
English