# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22621 | Jongwon Party (#40) | Unifying Values (KRIII5_UV) | C++14 | 323 ms | 1312 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 <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
long long arr[10010];
long long sum[10010];
int cnt[10010];
const int mod = 1000000007;
int e(int a, int x)
{
if(x == 0)
return 1;
if(x%2)
return 1LL * a * e(a, x-1) % mod;
int t = e(a, x/2);
return 1LL * t * t % mod;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int n, i, j;
scanf("%d", &n);
for(i = 1; i<=n; i++)
scanf("%lld", &arr[i]);
for(i = 1; i<=n; i++)
sum[i] = sum[i-1] + arr[i];
if(sum[n] == 0)
{
int c = 0;
for(i = 1; i<=n; i++)
if(sum[i] == 0)
c++;
if(c < 2)
{
printf("0");
return 0;
}
printf("%d", (0LL + e(2, c-1) - 1 + mod) % mod);
return 0;
}
int r = 0, mx;
long long b, t;
for(i = 1; i<n; i++)
{
if(sum[i] == 0 || sum[n]%sum[i] != 0)
continue;
b = sum[n]/sum[i];
if(b < 2 || b > n-i+1)
continue;
cnt[1] = 1;
mx = 1;
for(j = i+1; j<=n; j++)
{
if(sum[j]%sum[i] != 0)
continue;
t = sum[j]/sum[i];
if(t < 2 || t > b)
continue;
if(t == b && j != n)
continue;
cnt[t] = (0LL + cnt[t] + cnt[t - 1]) % mod;
mx = std::max(0LL + mx, t);
}
r = (0LL + r + cnt[b]) % mod;
for(j = 1; j<=mx; j++)
cnt[j] = 0;
}
printf("%d", r);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |