# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
23008 | cprayer | Unifying Values (KRIII5_UV) | C++14 | 0 ms | 0 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 <algorithm>
#include <set>
#include <map>
using namespace std;
const int MAXN = 1e4 + 9, MOD = 1e9 + 7;
long long A[MAXN];
int N;
pair<int, bool> dp[MAXN];
set<long long> chk;
int f(int i, int p, long long current, long long v){
auto &res = dp[p];
int c = 0;
cnt++;
if(i == N - 1) return ((current == v) && p) ? 1 : 0;
if(res.second) return res.first;
c += f(i + 1, p, current + A[i + 1], v);
c %= MOD;
if(current == v){
c += f(i + 1, i + 1, A[i + 1], v);
c %= MOD;
}
if(i == p) res.second = true;
return res.first = c;
}
int main(){
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%lld", &A[i]);
long long ans = 0, s = 0;
for(int i = 0; i < N; i++){
s += A[i];
if(chk.find(s) == chk.end()){
ans += f(i, 0, s, s);
chk.insert(s);
for(int j = 0; j < N; j++) dp[j] = make_pair(0, 0);
}
ans %= MOD;
}
printf("%lld", ans);
}