# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22413 | 2017-04-30T04:29:11 Z | past future present(#977, kazel, pjh0123, nemo) | Unifying Values (KRIII5_UV) | C++14 | 166 ms | 2216 KB |
#include<stdio.h> #include<string.h> #include<set> #include<vector> using namespace std; const int mod = 1e9 + 7; long long s[10000]; int n; int modpow(long long a, long long b) { return a*b%mod; } long long dp[10001]; vector<int> st; long long cz(int i) { if (i == n) return 1; if (dp[i] >= 0) return dp[i]; dp[i] = 0; long long sum = 0; for (int j = i; j < n; j++) { sum += s[j]; if (sum == 0) { dp[i] += cz(j + 1); } } dp[i] %= mod; return dp[i]; } long long foo(int i) { if (i == st.size()) return 1; if (dp[i] >= 0) return dp[i]; dp[i] = 0; int sum = 0; for (int j = i; j < st.size(); j++) { sum += st[j]; if (sum == 1) { dp[i] = (dp[i] + foo(j + 1)) % mod; } } return dp[i]; } set<long long> v; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", s + i); memset(dp, -1, sizeof(dp)); long long sum = 0, ans = cz(0); for (int i = 0; i < n; i++) sum += s[i]; if (sum == 0) ans--; sum = 0; v.insert(0); for (int b = 0; b < n - 1; b++) { sum += s[b]; if (v.find(sum) != v.end()) continue; v.insert(sum); long long ts = 0; st.clear(); int ncnt=0; for (int i = b + 1; i < n; i++) { ts += s[i]; if (ts == sum) { st.push_back(1); ts = 0; } else if (ts == -sum) { st.push_back(-1); ts = 0; } else if (ts == 0) { st.push_back(0); } } if (ncnt == 0 && ts == 0) { memset(dp, -1, sizeof(dp)); ans += foo(0); } } printf("%lld\n", ans%mod); }
Compilation message
# | 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 | Correct | 153 ms | 2212 KB | Output is correct |
5 | Correct | 126 ms | 2216 KB | Output is correct |
6 | Correct | 166 ms | 1672 KB | Output is correct |
7 | Incorrect | 76 ms | 1472 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 69 ms | 1472 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |