# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22562 | 2017-04-30T05:33:00 Z | 카시코이(#958, xdoju, ntopia, pps789) | Unifying Values (KRIII5_UV) | C++14 | 500 ms | 3408 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; if (allsum == 0) { long long targetsum = 0; vector<int> nxtp(n + 1); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; nxtp[j] = upper_bound(posv.begin(), posv.end(), j) - posv.begin(); } d[0][0] = 1; for (int k = 1; k <= n; ++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 = posv.begin() + nxtp[j]; while (it != posv.end()) { d[k % 2][*it] = (d[k % 2][*it] + d[1 - k % 2][j]) % MOD; ++it; } } if (k >= 2) ans += d[k % 2][n]; } printf("%d\n", ans % MOD); return 0; } for (int cnt : cand) { long long targetsum = allsum / cnt; vector<int> nxtp(n + 1); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; nxtp[j] = upper_bound(posv.begin(), posv.end(), j) - posv.begin(); } 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 = posv.begin() + nxtp[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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2172 KB | Output is correct |
2 | Correct | 0 ms | 2172 KB | Output is correct |
3 | Correct | 0 ms | 2172 KB | Output is correct |
4 | Execution timed out | 500 ms | 3408 KB | Execution timed out |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 500 ms | 2704 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |