#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<int, pair<long long, bool>>, int> m;
int f(int i, int current, long long v, bool divide){
int &res = m[{i, {current, divide}}];
if(i == N - 1) return current == v && divide ? 1 : 0;
if(res) return res;
res += f(i + 1, current + A[i + 1], v, divide);
res %= MOD;
if(current == v) res += f(i + 1, A[i + 1], v, true);
res %= MOD;
return res;
}
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:26:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
^
UV.cpp:27: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 |
211616 KB |
Execution timed out |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
500 ms |
8076 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |