# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22423 | 2017-04-30T04:32:25 Z | past future present(#977, kazel, pjh0123, nemo) | Unifying Values (KRIII5_UV) | C++14 | 159 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(); st.push_back(1); 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 (ts == 0) { memset(dp, -1, sizeof(dp)); for (int i : st) ts += i; ans += foo(0); if (ts == 1) ans--; } } printf("%lld\n", ans%mod); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 136 ms | 2216 KB | Output is correct |
5 | Correct | 159 ms | 2212 KB | Output is correct |
6 | Correct | 139 ms | 1676 KB | Output is correct |
7 | Correct | 76 ms | 1472 KB | Output is correct |
8 | Correct | 83 ms | 1472 KB | Output is correct |
9 | Correct | 63 ms | 1472 KB | Output is correct |
10 | Correct | 59 ms | 1472 KB | Output is correct |
11 | Correct | 63 ms | 1472 KB | Output is correct |
12 | Correct | 63 ms | 1472 KB | Output is correct |
13 | Correct | 79 ms | 1472 KB | Output is correct |
14 | Correct | 73 ms | 1472 KB | Output is correct |
15 | Correct | 76 ms | 1472 KB | Output is correct |
16 | Correct | 76 ms | 1472 KB | Output is correct |
17 | Correct | 63 ms | 1472 KB | Output is correct |
18 | Correct | 69 ms | 1472 KB | Output is correct |
19 | Correct | 109 ms | 1472 KB | Output is correct |
20 | Correct | 103 ms | 1472 KB | Output is correct |
21 | Correct | 86 ms | 1472 KB | Output is correct |
22 | Correct | 119 ms | 1524 KB | Output is correct |
23 | Correct | 149 ms | 1564 KB | Output is correct |
24 | Correct | 113 ms | 1576 KB | Output is correct |
25 | Correct | 103 ms | 1584 KB | Output is correct |
26 | Correct | 73 ms | 1584 KB | Output is correct |
27 | Correct | 69 ms | 1472 KB | Output is correct |
28 | Correct | 76 ms | 1472 KB | Output is correct |
29 | Correct | 79 ms | 1472 KB | Output is correct |
30 | Correct | 89 ms | 1472 KB | Output is correct |
31 | Correct | 86 ms | 1472 KB | Output is correct |
32 | Correct | 89 ms | 1472 KB | Output is correct |
33 | Correct | 83 ms | 1472 KB | Output is correct |
34 | Correct | 93 ms | 1472 KB | Output is correct |
35 | Correct | 99 ms | 1472 KB | Output is correct |
36 | Correct | 93 ms | 1472 KB | Output is correct |
37 | Correct | 103 ms | 1472 KB | Output is correct |
38 | Correct | 86 ms | 1472 KB | Output is correct |
39 | Correct | 79 ms | 1472 KB | Output is correct |
40 | Correct | 69 ms | 1472 KB | Output is correct |
41 | Correct | 89 ms | 1472 KB | Output is correct |
42 | Correct | 83 ms | 1472 KB | Output is correct |
43 | Correct | 79 ms | 1472 KB | Output is correct |
44 | Correct | 66 ms | 1472 KB | Output is correct |
45 | Correct | 76 ms | 1472 KB | Output is correct |
46 | Correct | 76 ms | 1472 KB | Output is correct |
47 | Correct | 89 ms | 1472 KB | Output is correct |
48 | Correct | 96 ms | 1472 KB | Output is correct |
49 | Correct | 83 ms | 1472 KB | Output is correct |
50 | Correct | 89 ms | 1472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 1472 KB | Output is correct |
2 | Correct | 63 ms | 1472 KB | Output is correct |
3 | Correct | 69 ms | 1472 KB | Output is correct |
4 | Correct | 56 ms | 1472 KB | Output is correct |
5 | Correct | 106 ms | 1472 KB | Output is correct |
6 | Correct | 116 ms | 1472 KB | Output is correct |
7 | Correct | 83 ms | 1472 KB | Output is correct |
8 | Correct | 76 ms | 1472 KB | Output is correct |
9 | Incorrect | 9 ms | 1332 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |