Submission #465702

# Submission time Handle Problem Language Result Execution time Memory
465702 2021-08-16T16:49:10 Z rainboy Klavir (COCI17_klavir) C
160 / 160
232 ms 23972 KB
/* https://oj.uz/submission/101414 (Benq) */
#include <stdio.h>

#define N	1000000
#define MD	1000000007

int main() {
	static int aa[N], ff[N + 1], dp[N + 1];
	int n, m, i, j;

	scanf("%d%d", &m, &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	ff[0] = -1, ff[1] = 0;
	for (i = -1, j = 0; j < n; i++, j++) {
		while (i >= 0 && aa[i] != aa[j])
			i = ff[i];
		ff[j + 1] = i + 1;
		dp[j + 1] = j == 0 ? m : ((long long) (dp[j] - dp[ff[j]] + MD) * m + dp[i + 1]) % MD;
		printf("%d\n", dp[j + 1]);
	}
	return 0;
}

Compilation message

klavir.c: In function 'main':
klavir.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d", &m, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
klavir.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2592 KB Output is correct
2 Correct 221 ms 20840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 23972 KB Output is correct
2 Correct 214 ms 20860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 23876 KB Output is correct
2 Correct 218 ms 20804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 231 ms 23972 KB Output is correct
2 Correct 214 ms 20832 KB Output is correct