# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22543 | 2017-04-30T05:26:10 Z | 카시코이(#958, xdoju, ntopia, pps789) | Unifying Values (KRIII5_UV) | C++14 | 500 ms | 3272 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 d[2][10004]; 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); } vector<int> cand; for (int i = 2; i <= n; ++i) { if (allsum % i == 0) { cand.push_back(i); } } long long ans = 0; for (int cnt : cand) { long long targetsum = allsum / cnt; d[0][0] = 1; for (int k = 1; k <= cnt; ++k) { memset(d[k % 2], 0, sizeof(d[k % 2])); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; auto it = upper_bound(posv.begin(), posv.end(), j); while (it != posv.end()) { d[k % 2][*it] = (d[k % 2][*it] + d[1 - k % 2][j]) % MOD; ++it; } } } ans += d[cnt % 2][n]; } printf("%d\n", ans % MOD); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2168 KB | Output is correct |
2 | Correct | 0 ms | 2168 KB | Output is correct |
3 | Correct | 0 ms | 2168 KB | Output is correct |
4 | Execution timed out | 500 ms | 3272 KB | Execution timed out |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 500 ms | 2608 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |