#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
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]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1216 KB |
Output is correct |
2 |
Correct |
0 ms |
1216 KB |
Output is correct |
3 |
Correct |
0 ms |
1216 KB |
Output is correct |
4 |
Execution timed out |
500 ms |
205596 KB |
Execution timed out |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
500 ms |
178800 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |