# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22673 | 카시코이 (#40) | Unifying Values (KRIII5_UV) | C++14 | 156 ms | 4596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;
int n;
long long arr[10004];
long long sum[10004];
long long allsum;
int main() {
//freopen("input.txt", "r", stdin);
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &arr[i]);
sum[i] = sum[i - 1] + arr[i];
}
allsum = sum[n];
long long ans = 0;
if (allsum == 0) {
int ppcnt = 0;
long long ss = 0;
for (int i = 1; i <= n; ++i) {
ss += arr[i];
if (ss == 0) {
++ppcnt;
}
}
ans = 1;
for (int k = 1; k < ppcnt; ++k) {
ans = (ans * 2ll) % MOD;
}
ans = (ans - 1 + MOD) % MOD;
printf("%d\n", ans);
return 0;
}
vector<int> cand;
for (int i = 2; i <= n; ++i) {
if (allsum % i == 0) {
cand.push_back(i);
}
}
vector<vector<int>> sum1(n + 1), prefix(n + 1);
for (int cnt : cand) {
long long targetsum = allsum / cnt;
vector<vector<int>> idxs(n + 1);
for (int i = 0; i <= n; ++i) {
if (llabs(sum[i]) % llabs(targetsum) == 0) {
long long mcnt = sum[i] / targetsum;
if (0 <= mcnt && mcnt <= cnt) {
idxs[mcnt].push_back(i);
}
}
}
idxs[0] = vector<int>{ 0 };
sum1[0] = vector<int>{ 1 };
prefix[0] = vector<int>{ 1 };
for (int k = 1; k <= cnt; ++k) {
sum1[k].resize(idxs[k].size(), 0);
prefix[k].resize(idxs[k].size(), 0);
int p = 0;
for (int j = 0; j < idxs[k].size(); ++j) {
while (p < idxs[k - 1].size() && idxs[k - 1][p] < idxs[k][j]) {
++p;
}
sum1[k][j] = (p == 0) ? 0 : prefix[k - 1][p - 1];
prefix[k][j] = (j == 0 ? 0 : prefix[k][j - 1]) + sum1[k][j];
prefix[k][j] %= MOD;
}
}
ans += sum1[cnt].back();
}
printf("%d\n", ans % MOD);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |