#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> tab, int n, int x){
vector<int> tab2(n, tab[0]);
for(int i=1; i<n; i++){
tab2[i] = tab[i] - tab[i-1];
}
for(int i=0; i<n; i++){
int val = tab2[i];
// cout << val << " ";
if(val < 0 || (val > 0 && i > n-x)){
return 0;
}
if(i+x < n) tab2[i+x] += val;
}
return 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> tab(n);
long long int sum = 0;
for(int i=0; i<n; i++){
cin >> tab[i];
sum += tab[i];
}
for(int i=n; i>=1; i--){
if(sum%i == 0 && check(tab, n, i)){
cout << i;
return 0;
}
// if(sum%i == 0) cout << "\n";
}
}
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 | #include <bits/stdc++.h> using namespace std; bool check(vector<int> tab, int n, int x){ vector<int> tab2(n, tab[0]); for(int i=1; i<n; i++){ tab2[i] = tab[i] - tab[i-1]; } for(int i=0; i<n; i++){ int val = tab2[i]; // cout << val << " "; if(val < 0 || (val > 0 && i > n-x)){ return 0; } if(i+x < n) tab2[i+x] += val; } return 1; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> tab(n); long long int sum = 0; for(int i=0; i<n; i++){ cin >> tab[i]; sum += tab[i]; } for(int i=n; i>=1; i--){ if(sum%i == 0 && check(tab, n, i)){ cout << i; return 0; } // if(sum%i == 0) cout << "\n"; } } |
English