# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22936 | dotorya | Unifying Values (KRIII5_UV) | C++14 | 163 ms | 5928 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 <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 1034567890123456789ll;
const db PI = acos(-1);
const db ERR = 1E-11;
ll sum[100050];
ll in[100050];
ll dp[100050];
ll sum2[100050];
ll po2[100050];
int main() {
int N, i, j;
scanf("%d", &N);
for (i = 1; i <= N; i++) {
scanf("%lld", &in[i]);
sum[i] = sum[i - 1] + in[i];
}
ll ans = 0;
po2[0] = 1;
for (i = 1; i <= 100000; i++) po2[i] = po2[i - 1] * 2 % MOD;
if (sum[N] == 0) {
int c = 0;
for (i = 1; i < N; i++) if (sum[i] == 0) c++;
return !printf("%lld\n", po2[c] - 1);
}
for (i = 2; i <= N; i++) {
if (sum[N] % i) continue;
ll v = sum[N] / i;
dp[0] = 1;
sum2[0] = 1;
for (j = 1; j <= N; j++) {
ll t = sum[j] / v;
if (t <= 0 || t > i || t * v != sum[j]) continue;
dp[j] = sum2[t - 1];
sum2[t] = (sum2[t] + dp[j]) % MOD;
}
ans = (ans + dp[N]) % MOD;
for (j = 0; j <= i; j++) sum2[j] = 0;
}
return !printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |