Submission #465575

#TimeUsernameProblemLanguageResultExecution timeMemory
465575rainboyKlavir (COCI17_klavir)C11
32 / 160
319 ms65536 KiB
#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)

klavir.c: In function 'append':
klavir.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
klavir.c: In function 'main':
klavir.c:21:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d%d", &m, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
klavir.c:23:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...