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;
int A[MAXN];
int N;
set<long long> chk;
map<pair<long long, pair<long long, bool>>, pair<int, bool>> m;
int f(int i, long long current, long long v, bool divide){
auto &res = m[{i, {current, divide}}];
if(i == N - 1){
res.first = current == v && divide ? 1 : 0;
res.second = true;
}
if(res.second) return res.first;
res.second = true;
res.first += f(i + 1, current + A[i + 1], v, divide);
res.first %= MOD;
if(current == v) res.first += f(i + 1, A[i + 1], v, true);
res.first %= MOD;
return res.first;
}
int main(){
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%d", &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, s, s, false);
chk.insert(s);
m.clear();
}
ans %= MOD;
}
printf("%lld", ans);
}
Compilation message (stderr)
UV.cpp: In function 'int main()':
UV.cpp:30:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
UV.cpp:31:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i = 0; i < N; i++) scanf("%d", &A[i]);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |