# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22320 | past future present (#40) | Repeating Subsequence Tests (KRIII5_RST) | C++14 | 0 ms | 1332 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<stdio.h>
#include<string.h>
#include<set>
using namespace std;
const int mod = 1e9 + 7;
long long s[10000];
int n;
int modpow(long long a, long long b)
{
return a*b%mod;
}
long long dp[10001];
long long cz(int i)
{
if (i == n) return 1;
if (dp[i] >= 0) return dp[i];
dp[i] = 0;
long long sum = 0;
for (int j = i; j < n; j++)
{
sum += s[j];
if (sum == 0)
{
dp[i] += cz(j + 1);
}
}
dp[i] %= mod;
return dp[i];
}
set<long long> v;
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lld", s + i);
memset(dp, -1, sizeof(dp));
long long sum = 0, ans = cz(0);
for (int i = 0; i < n; i++) sum += s[i];
if (sum == 0) ans--;
sum = 0;
v.insert(0);
for (int b = 0; b < n - 1; b++)
{
sum += s[b];
if (v.find(sum) != v.end()) continue;
v.insert(sum);
long long ts = 0, zst=0, ta=1;
for (int i = b + 1; i < n; i++)
{
ts += s[i];
if (ts == sum)
{
ta = modpow(ta, zst + 1);
ts = zst = 0;
}
else if (ts == 0)
{
zst++;
}
}
if (ts != sum && ts != 0) ta = 0;
ans += ta;
}
printf("%lld\n", ans%mod);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |