#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using LL = long long;
bool static check(int x, int n, const vector<int>& a)
{
vector<int> ends(n + 1);
int cnt = 0;
for (int i = 0; i < n; ++i)
{
cnt -= ends[i];
if (cnt > a[i])
return false;
if (cnt < a[i])
{
if (i + x > n)
return false;
ends[i + x] = a[i] - cnt;
cnt = a[i];
}
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
LL sum = 0;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
sum += a[i];
}
vector<int> factors;
for (int i = 2; i <= n; ++i)
{
if (sum % i == 0)
factors.push_back(i);
}
int res = 1;
if (factors.size() > 0)
{
for (int i = factors.size() - 1; i >= 0; --i)
{
if (check(factors[i], n, a))
{
res = factors[i];
break;
}
}
}
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #include <algorithm> #include <iostream> #include <vector> using namespace std; using LL = long long; bool static check(int x, int n, const vector<int>& a) { vector<int> ends(n + 1); int cnt = 0; for (int i = 0; i < n; ++i) { cnt -= ends[i]; if (cnt > a[i]) return false; if (cnt < a[i]) { if (i + x > n) return false; ends[i + x] = a[i] - cnt; cnt = a[i]; } } return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); LL sum = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } vector<int> factors; for (int i = 2; i <= n; ++i) { if (sum % i == 0) factors.push_back(i); } int res = 1; if (factors.size() > 0) { for (int i = factors.size() - 1; i >= 0; --i) { if (check(factors[i], n, a)) { res = factors[i]; break; } } } cout << res << "\n"; return 0; } |
English