# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465575 | rainboy | Klavir (COCI17_klavir) | C11 | 319 ms | 65536 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 <stdlib.h>
#define N 1000000
#define MD 1000000007
int *ej[N + 1], eo[N + 1];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
int main() {
static int aa[N], dp[N + 1], dq[N + 1], ff[N + 1];
int n, m, i, j;
scanf("%d%d", &m, &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0; i <= n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
ff[0] = -1, ff[1] = 0;
for (i = 0, j = 1; j < n; i++, j++) {
while (i >= 0 && aa[i] != aa[j])
i = ff[i];
ff[j + 1] = i + 1;
append(i + 1, j + 1);
}
dp[0] = 0;
for (i = 1; i <= n; i++) {
int o;
if (i > 1)
dq[i - 1] = (dq[i - 1] + dq[ff[i - 1]]) % MD;
dp[i] = ((long long) (dp[i - 1] + 1) * m - dq[i - 1]) % MD;
dq[i - 1] = (dq[i - 1] + dp[i]) % MD;
for (o = eo[i]; o--; ) {
j = ej[i][o];
dq[j - 1] = (dq[j - 1] - dp[i]) % MD;
}
}
for (i = 1; i <= n; i++)
printf("%d\n", dp[i]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |