Submission #23009

#TimeUsernameProblemLanguageResultExecution timeMemory
23009cprayerUnifying Values (KRIII5_UV)C++14
0 / 7
500 ms1988 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...