#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> nums;
ll n;
bool is_possible(ll k){
ll i;
vector<ll> s(n);
s[0] = nums[0];
for(i=1; i<n; ++i){
s[i] = nums[i]-nums[i-1];
if(i>=k) s[i]+=s[i-k];
if(s[i]<0) return false;
if(i>n-k && s[i]>0) return false;
}
return true;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
ll i, sum=0;
nums.resize(n);
for(i=0; i<n; ++i){ cin >> nums[i]; sum+=nums[i];}
ll L, R;
for(L=1; L<n; ++L) if(nums[L]<nums[L-1]) break;
for(R=n-2; R>=0; R--) if(nums[R]<nums[R+1]) break;
for(i=min(L, n-R-1); i>=1; i--){
if(sum%i!=0) continue;
if(is_possible(i)){ cout << i; return 0;}
}
cout << 1;
}
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 | #include<bits/stdc++.h> using namespace std; #define ll long long vector<ll> nums; ll n; bool is_possible(ll k){ ll i; vector<ll> s(n); s[0] = nums[0]; for(i=1; i<n; ++i){ s[i] = nums[i]-nums[i-1]; if(i>=k) s[i]+=s[i-k]; if(s[i]<0) return false; if(i>n-k && s[i]>0) return false; } return true; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; ll i, sum=0; nums.resize(n); for(i=0; i<n; ++i){ cin >> nums[i]; sum+=nums[i];} ll L, R; for(L=1; L<n; ++L) if(nums[L]<nums[L-1]) break; for(R=n-2; R>=0; R--) if(nums[R]<nums[R+1]) break; for(i=min(L, n-R-1); i>=1; i--){ if(sum%i!=0) continue; if(is_possible(i)){ cout << i; return 0;} } cout << 1; } |
English