// Author : Jakub Rozek
// Task : BUR – Bursztyny [C]
// Memory : n + D(S);
// Time : n * D(S);
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll sum = 0;
vector<ll> start, a;
vector<int> dzielniki;
bool check(int k) {
ll active = 0, need;
for (int i = 1; i <= n; ++i) {
if (i - k >= 1) {
active -= start[i - k];
}
if (i+k-1 <= n) {
need = a[i] - active;
if (need < 0) return false;
start[i] = need;
active += need;
} else if (active != a[i]) {
return false;
}
}
return true;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
start.resize(n+1);
a.resize(n+1);
for (int i=1; i<=n; ++i) {
cin >> a[i];
sum += a[i];
}
for (ll d=1; d*d<=sum; ++d) {
if (sum % d != 0) continue;
if (d <= n) {
dzielniki.push_back((int)d);
}
ll d2 = sum / d;
if (d2 != d && d2 <= n) {
dzielniki.push_back((int)d2);
}
}
sort(dzielniki.rbegin(), dzielniki.rend());
for (int k : dzielniki) {
if (check(k)) {
cout << k << '\n';
return 0;
}
}
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | // Author : Jakub Rozek // Task : BUR – Bursztyny [C] // Memory : n + D(S); // Time : n * D(S); #include <bits/stdc++.h> using namespace std; using ll = long long; int n; ll sum = 0; vector<ll> start, a; vector<int> dzielniki; bool check(int k) { ll active = 0, need; for (int i = 1; i <= n; ++i) { if (i - k >= 1) { active -= start[i - k]; } if (i+k-1 <= n) { need = a[i] - active; if (need < 0) return false; start[i] = need; active += need; } else if (active != a[i]) { return false; } } return true; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; start.resize(n+1); a.resize(n+1); for (int i=1; i<=n; ++i) { cin >> a[i]; sum += a[i]; } for (ll d=1; d*d<=sum; ++d) { if (sum % d != 0) continue; if (d <= n) { dzielniki.push_back((int)d); } ll d2 = sum / d; if (d2 != d && d2 <= n) { dzielniki.push_back((int)d2); } } sort(dzielniki.rbegin(), dzielniki.rend()); for (int k : dzielniki) { if (check(k)) { cout << k << '\n'; return 0; } } return 0; } |
English