#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
LL n;
cin>>n;
vector<LL>v(n);
LL suma=0;
for(auto &x : v){
cin>>x;
suma+=x;
}
vector<LL> dz;
for(LL i=2; i<=min(n, suma); i++){
if(suma%i==0){
dz.push_back(i);
}
}
LL res = 1;
for(auto d : dz){
queue<pair<LL, LL>> q;
LL act = 0;
bool ok=true;
for(LL i=0; i<n; i++){
if(!q.empty() && q.front().second+d==i){
act-=q.front().first;
q.pop();
}
if(act > v[i]){
ok=false;
break;
}else if(act < v[i]){
if(i+d>n){
ok=false;
break;
}
q.push({v[i]-act, i});
act=v[i];
}
}
if(ok)res = max(res, d);
}
cout<<res<<"\n";
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 | #include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); LL n; cin>>n; vector<LL>v(n); LL suma=0; for(auto &x : v){ cin>>x; suma+=x; } vector<LL> dz; for(LL i=2; i<=min(n, suma); i++){ if(suma%i==0){ dz.push_back(i); } } LL res = 1; for(auto d : dz){ queue<pair<LL, LL>> q; LL act = 0; bool ok=true; for(LL i=0; i<n; i++){ if(!q.empty() && q.front().second+d==i){ act-=q.front().first; q.pop(); } if(act > v[i]){ ok=false; break; }else if(act < v[i]){ if(i+d>n){ ok=false; break; } q.push({v[i]-act, i}); act=v[i]; } } if(ok)res = max(res, d); } cout<<res<<"\n"; return 0; } |
English