# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22542 | 2000/4000 (#40) | Unifying Values (KRIII5_UV) | C++14 | 59 ms | 1992 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <map>
using namespace std;
const int MAXN = 10004;
const int P = 1000 * 1000 * 1000 + 7;
typedef long long lli;
int N;
lli S[MAXN];
lli D[MAXN];
map<lli,int> dp;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%lld", &D[i]);
S[i] += S[i - 1] + D[i];
}
int cnt = 0;
for (int i = 1; i < N; ++i) {
// 1 ~ i
const lli st = S[i] - S[0];
if (st == 0 || S[N] % st != 0) continue;
dp.clear();
dp[S[N]] = 1;
for (int j = N - 1; j > i; --j) {
auto it = dp.find(S[j] + st);
if (it == dp.end()) continue;
else dp[S[j]] = (dp[S[j]] + it->second) % P;
}
cnt = (cnt + dp[S[i] + st]) % P;
}
printf("%d\n", cnt);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |