#include <bits/stdc++.h>
using namespace std;
int main () {
ios_base::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto& x: a) cin >> x;
int64_t tot = accumulate(a.begin(), a.end(), 0LL);
auto check = [&] (int k) -> bool {
if (tot%k != 0) return 0;
int s = 0;
vector<int> b(n);
for (int i = 0; i < n; i++) {
if (i >= k) s -= b[i-k];
int d = a[i] - s;
if (d < 0 || (d > 0 && i+k > n)) return 0;
b[i] = d;
s += d;
}
return 1;
};
for (int i = n; i >= 1; i--) {
if (check(i)) {
cout << i << '\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 | #include <bits/stdc++.h> using namespace std; int main () { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto& x: a) cin >> x; int64_t tot = accumulate(a.begin(), a.end(), 0LL); auto check = [&] (int k) -> bool { if (tot%k != 0) return 0; int s = 0; vector<int> b(n); for (int i = 0; i < n; i++) { if (i >= k) s -= b[i-k]; int d = a[i] - s; if (d < 0 || (d > 0 && i+k > n)) return 0; b[i] = d; s += d; } return 1; }; for (int i = n; i >= 1; i--) { if (check(i)) { cout << i << '\n'; return 0; } } } |
English