#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define v vector
#define ALL(_) _.begin(), _.end()
#define pb push_back
#define FF first
#define SS second
ll ile;
v<ll>aa;
bool da_sie(ll wielk){
v<ll>kon(ile, 0);
ll akt = 0;
for(ll i=0;i<ile;i++){
if(akt > aa[i]) return false;
if(akt < aa[i]){
if(i + wielk - 1 < ile){
kon[i+wielk - 1] += aa[i] - akt;
}
else{
return false;
}
akt = aa[i];
}
akt -= kon[i];
}
return true;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>ile;
aa.resize(ile);
ll sum = 0;
for(ll i=0;i<ile;i++){
cin>>aa[i];
sum += aa[i];
}
for(ll i = min(ile, sum);i>1;i--){
if(sum % i == 0 && da_sie(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 40 41 42 43 44 45 | #include<bits/stdc++.h> using namespace std; #define ll long long #define v vector #define ALL(_) _.begin(), _.end() #define pb push_back #define FF first #define SS second ll ile; v<ll>aa; bool da_sie(ll wielk){ v<ll>kon(ile, 0); ll akt = 0; for(ll i=0;i<ile;i++){ if(akt > aa[i]) return false; if(akt < aa[i]){ if(i + wielk - 1 < ile){ kon[i+wielk - 1] += aa[i] - akt; } else{ return false; } akt = aa[i]; } akt -= kon[i]; } return true; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>ile; aa.resize(ile); ll sum = 0; for(ll i=0;i<ile;i++){ cin>>aa[i]; sum += aa[i]; } for(ll i = min(ile, sum);i>1;i--){ if(sum % i == 0 && da_sie(i)){ cout<<i; return 0; } } cout<<1; } |
English