# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22651 | 2017-04-30T06:07:37 Z | 카시코이(#958, xdoju, ntopia, pps789) | Unifying Values (KRIII5_UV) | C++14 | 13 ms | 4068 KB |
#include <cstdio> #include <cstring> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; const int MOD = 1000000007; int n; long long arr[10004]; long long sum[10004]; long long allsum; int main() { //freopen("input.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &arr[i]); sum[i] = sum[i - 1] + arr[i]; } allsum = sum[n]; unordered_map<long long, vector<int>> posbysum; for (int i = 0; i <= n; ++i) { posbysum[sum[i]]; posbysum[sum[i]].push_back(i); } long long ans = 0; if (allsum == 0) { int ppcnt = 0; long long ss = 0; for (int i = 1; i <= n; ++i) { ss += arr[i]; if (ss == 0) { ++ppcnt; } } ans = 1; for (int k = 1; k < ppcnt; ++k) { ans = (ans * 2ll) % MOD; } ans = (ans - 1 + MOD) % MOD; printf("%d\n", ans); return 0; } vector<int> cand; for (int i = 2; i <= n; ++i) { if (allsum % i == 0) { cand.push_back(i); } } for (int cnt : cand) { long long targetsum = allsum / cnt; vector<vector<int>> sum1(n + 1), prefix(n + 1); vector<int>& idxsfst = posbysum[0]; sum1[0].assign(idxsfst.size(), 0); prefix[0].assign(idxsfst.size(), 0); sum1[0][0] = 1; prefix[0][0] = 1; for (int k = 1; k <= cnt; ++k) { long long ss = targetsum * k; long long prvss = targetsum * (k - 1); vector<int>& idxsk = posbysum[ss]; vector<int>& prvidxsk = posbysum[prvss]; sum1[k].resize(idxsk.size()); prefix[k].resize(idxsk.size()); int p = 0; for (int j = 0; j < idxsk.size(); ++j) { while (p < prvidxsk.size() && prvidxsk[p] < idxsk[j]) { ++p; } sum1[k][j] = (p == 0) ? 0 : prefix[k - 1][p - 1]; prefix[k][j] = (j == 0 ? 0 : prefix[k][j - 1]) + sum1[k][j]; prefix[k][j] %= MOD; } } ans += sum1[cnt].back(); } printf("%d\n", ans % MOD); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2096 KB | Output is correct |
2 | Correct | 0 ms | 2096 KB | Output is correct |
3 | Correct | 0 ms | 2096 KB | Output is correct |
4 | Correct | 3 ms | 4068 KB | Output is correct |
5 | Correct | 13 ms | 4068 KB | Output is correct |
6 | Correct | 0 ms | 2236 KB | Output is correct |
7 | Incorrect | 3 ms | 3024 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 3152 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |