Submission #23003

# Submission time Handle Problem Language Result Execution time Memory
23003 2017-05-01T07:31:38 Z cprayer Unifying Values (KRIII5_UV) C++14
0 / 7
500 ms 211616 KB
#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]);
                                                  ^
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Execution timed out 500 ms 8076 KB Execution timed out
2 Halted 0 ms 0 KB -