Submission #23009

# Submission time Handle Problem Language Result Execution time Memory
23009 2017-05-01T11:37:55 Z cprayer Unifying Values (KRIII5_UV) C++14
0 / 7
500 ms 1988 KB
#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;
    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;
    }
    else return 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);
}

Compilation message

UV.cpp: In function 'int main()':
UV.cpp:33:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
UV.cpp:34:52: 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("%lld", &A[i]);
                                                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1332 KB Output is correct
2 Correct 0 ms 1332 KB Output is correct
3 Correct 0 ms 1332 KB Output is correct
4 Execution timed out 500 ms 1984 KB Execution timed out
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 500 ms 1988 KB Execution timed out
2 Halted 0 ms 0 KB -