#include <stdio.h>
#define N 1000000
#define MD 1000003
int vv[N + 1], ff[N + 1], gg[N + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= N; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int main() {
static int kk[N];
int n, k, i, r, a, k1, k01;
init();
scanf("%d%d", &n, &k);
for (i = 0; i + k <= n; i++)
scanf("%d", &kk[i]);
k01 = k1 = 0;
for (r = 0; r < k; r++) {
a = -1;
for (i = r; i + k < n; i += k)
if (kk[i + 1] != kk[i]) {
if (kk[i + 1] - kk[i] == 1)
a = 0;
else if (kk[i + 1] - kk[i] == -1)
a = 1;
else
a = -2;
break;
}
if (a == -2) {
printf("0\n");
return 0;
}
if (a == -1) {
k01++;
continue;
}
if (a == 1)
k1++;
for (i = r; i + k < n; i += k) {
a += kk[i + 1] - kk[i];
if (a != 0 && a != 1) {
printf("0\n");
return 0;
}
}
}
printf("%d\n", choose(k01, kk[0] - k1));
return 0;
}
Compilation message
Main.c: In function 'main':
Main.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%d", &n, &k);
| ^~~~~~~~~~~~~~~~~~~~~
Main.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d", &kk[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
13 |
Correct |
10 ms |
11988 KB |
Output is correct |
14 |
Correct |
10 ms |
11988 KB |
Output is correct |
15 |
Correct |
11 ms |
11940 KB |
Output is correct |
16 |
Correct |
10 ms |
11912 KB |
Output is correct |
17 |
Correct |
10 ms |
11988 KB |
Output is correct |
18 |
Correct |
11 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11980 KB |
Output is correct |
21 |
Correct |
13 ms |
11972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
13 |
Correct |
10 ms |
11988 KB |
Output is correct |
14 |
Correct |
10 ms |
11988 KB |
Output is correct |
15 |
Correct |
11 ms |
11940 KB |
Output is correct |
16 |
Correct |
10 ms |
11912 KB |
Output is correct |
17 |
Correct |
10 ms |
11988 KB |
Output is correct |
18 |
Correct |
11 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11980 KB |
Output is correct |
21 |
Correct |
13 ms |
11972 KB |
Output is correct |
22 |
Correct |
11 ms |
12020 KB |
Output is correct |
23 |
Correct |
10 ms |
11988 KB |
Output is correct |
24 |
Correct |
11 ms |
11928 KB |
Output is correct |
25 |
Correct |
10 ms |
11936 KB |
Output is correct |
26 |
Correct |
10 ms |
12000 KB |
Output is correct |
27 |
Correct |
11 ms |
11944 KB |
Output is correct |
28 |
Correct |
10 ms |
11988 KB |
Output is correct |
29 |
Correct |
11 ms |
12020 KB |
Output is correct |
30 |
Correct |
12 ms |
11988 KB |
Output is correct |
31 |
Correct |
10 ms |
11988 KB |
Output is correct |
32 |
Correct |
10 ms |
11920 KB |
Output is correct |
33 |
Correct |
10 ms |
12028 KB |
Output is correct |
34 |
Correct |
11 ms |
11944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
13 |
Correct |
10 ms |
11988 KB |
Output is correct |
14 |
Correct |
10 ms |
11988 KB |
Output is correct |
15 |
Correct |
11 ms |
11940 KB |
Output is correct |
16 |
Correct |
10 ms |
11912 KB |
Output is correct |
17 |
Correct |
10 ms |
11988 KB |
Output is correct |
18 |
Correct |
11 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11980 KB |
Output is correct |
21 |
Correct |
13 ms |
11972 KB |
Output is correct |
22 |
Correct |
11 ms |
12020 KB |
Output is correct |
23 |
Correct |
10 ms |
11988 KB |
Output is correct |
24 |
Correct |
11 ms |
11928 KB |
Output is correct |
25 |
Correct |
10 ms |
11936 KB |
Output is correct |
26 |
Correct |
10 ms |
12000 KB |
Output is correct |
27 |
Correct |
11 ms |
11944 KB |
Output is correct |
28 |
Correct |
10 ms |
11988 KB |
Output is correct |
29 |
Correct |
11 ms |
12020 KB |
Output is correct |
30 |
Correct |
12 ms |
11988 KB |
Output is correct |
31 |
Correct |
10 ms |
11988 KB |
Output is correct |
32 |
Correct |
10 ms |
11920 KB |
Output is correct |
33 |
Correct |
10 ms |
12028 KB |
Output is correct |
34 |
Correct |
11 ms |
11944 KB |
Output is correct |
35 |
Correct |
68 ms |
15832 KB |
Output is correct |
36 |
Correct |
73 ms |
15824 KB |
Output is correct |
37 |
Correct |
73 ms |
15900 KB |
Output is correct |
38 |
Correct |
74 ms |
15876 KB |
Output is correct |
39 |
Correct |
68 ms |
15916 KB |
Output is correct |
40 |
Correct |
74 ms |
15808 KB |
Output is correct |
41 |
Correct |
74 ms |
15820 KB |
Output is correct |
42 |
Correct |
75 ms |
15876 KB |
Output is correct |
43 |
Correct |
71 ms |
15820 KB |
Output is correct |
44 |
Correct |
68 ms |
15896 KB |
Output is correct |
45 |
Correct |
77 ms |
15812 KB |
Output is correct |
46 |
Correct |
67 ms |
15900 KB |
Output is correct |
47 |
Correct |
68 ms |
15896 KB |
Output is correct |
48 |
Correct |
72 ms |
15876 KB |
Output is correct |
49 |
Correct |
73 ms |
15900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
13 |
Correct |
10 ms |
11988 KB |
Output is correct |
14 |
Correct |
10 ms |
11988 KB |
Output is correct |
15 |
Correct |
11 ms |
11940 KB |
Output is correct |
16 |
Correct |
10 ms |
11912 KB |
Output is correct |
17 |
Correct |
10 ms |
11988 KB |
Output is correct |
18 |
Correct |
11 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11980 KB |
Output is correct |
21 |
Correct |
13 ms |
11972 KB |
Output is correct |
22 |
Correct |
11 ms |
12020 KB |
Output is correct |
23 |
Correct |
10 ms |
11988 KB |
Output is correct |
24 |
Correct |
11 ms |
11928 KB |
Output is correct |
25 |
Correct |
10 ms |
11936 KB |
Output is correct |
26 |
Correct |
10 ms |
12000 KB |
Output is correct |
27 |
Correct |
11 ms |
11944 KB |
Output is correct |
28 |
Correct |
10 ms |
11988 KB |
Output is correct |
29 |
Correct |
11 ms |
12020 KB |
Output is correct |
30 |
Correct |
12 ms |
11988 KB |
Output is correct |
31 |
Correct |
10 ms |
11988 KB |
Output is correct |
32 |
Correct |
10 ms |
11920 KB |
Output is correct |
33 |
Correct |
10 ms |
12028 KB |
Output is correct |
34 |
Correct |
11 ms |
11944 KB |
Output is correct |
35 |
Correct |
68 ms |
15832 KB |
Output is correct |
36 |
Correct |
73 ms |
15824 KB |
Output is correct |
37 |
Correct |
73 ms |
15900 KB |
Output is correct |
38 |
Correct |
74 ms |
15876 KB |
Output is correct |
39 |
Correct |
68 ms |
15916 KB |
Output is correct |
40 |
Correct |
74 ms |
15808 KB |
Output is correct |
41 |
Correct |
74 ms |
15820 KB |
Output is correct |
42 |
Correct |
75 ms |
15876 KB |
Output is correct |
43 |
Correct |
71 ms |
15820 KB |
Output is correct |
44 |
Correct |
68 ms |
15896 KB |
Output is correct |
45 |
Correct |
77 ms |
15812 KB |
Output is correct |
46 |
Correct |
67 ms |
15900 KB |
Output is correct |
47 |
Correct |
68 ms |
15896 KB |
Output is correct |
48 |
Correct |
72 ms |
15876 KB |
Output is correct |
49 |
Correct |
73 ms |
15900 KB |
Output is correct |
50 |
Correct |
79 ms |
15896 KB |
Output is correct |
51 |
Correct |
103 ms |
15824 KB |
Output is correct |
52 |
Correct |
80 ms |
15836 KB |
Output is correct |
53 |
Correct |
87 ms |
15888 KB |
Output is correct |
54 |
Correct |
87 ms |
15896 KB |
Output is correct |
55 |
Correct |
82 ms |
15876 KB |
Output is correct |
56 |
Correct |
80 ms |
15900 KB |
Output is correct |
57 |
Correct |
74 ms |
15876 KB |
Output is correct |
58 |
Correct |
102 ms |
15868 KB |
Output is correct |
59 |
Correct |
79 ms |
15792 KB |
Output is correct |
60 |
Correct |
75 ms |
15824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11940 KB |
Output is correct |
2 |
Correct |
10 ms |
11988 KB |
Output is correct |
3 |
Correct |
10 ms |
11988 KB |
Output is correct |
4 |
Correct |
11 ms |
11988 KB |
Output is correct |
5 |
Correct |
11 ms |
11996 KB |
Output is correct |
6 |
Correct |
13 ms |
11940 KB |
Output is correct |
7 |
Correct |
11 ms |
11988 KB |
Output is correct |
8 |
Correct |
10 ms |
11988 KB |
Output is correct |
9 |
Correct |
11 ms |
11988 KB |
Output is correct |
10 |
Correct |
10 ms |
11988 KB |
Output is correct |
11 |
Correct |
11 ms |
11988 KB |
Output is correct |
12 |
Correct |
10 ms |
11988 KB |
Output is correct |
13 |
Correct |
10 ms |
11988 KB |
Output is correct |
14 |
Correct |
10 ms |
11988 KB |
Output is correct |
15 |
Correct |
11 ms |
11940 KB |
Output is correct |
16 |
Correct |
10 ms |
11912 KB |
Output is correct |
17 |
Correct |
10 ms |
11988 KB |
Output is correct |
18 |
Correct |
11 ms |
11988 KB |
Output is correct |
19 |
Correct |
10 ms |
11988 KB |
Output is correct |
20 |
Correct |
10 ms |
11980 KB |
Output is correct |
21 |
Correct |
13 ms |
11972 KB |
Output is correct |
22 |
Correct |
11 ms |
12020 KB |
Output is correct |
23 |
Correct |
10 ms |
11988 KB |
Output is correct |
24 |
Correct |
11 ms |
11928 KB |
Output is correct |
25 |
Correct |
10 ms |
11936 KB |
Output is correct |
26 |
Correct |
10 ms |
12000 KB |
Output is correct |
27 |
Correct |
11 ms |
11944 KB |
Output is correct |
28 |
Correct |
10 ms |
11988 KB |
Output is correct |
29 |
Correct |
11 ms |
12020 KB |
Output is correct |
30 |
Correct |
12 ms |
11988 KB |
Output is correct |
31 |
Correct |
10 ms |
11988 KB |
Output is correct |
32 |
Correct |
10 ms |
11920 KB |
Output is correct |
33 |
Correct |
10 ms |
12028 KB |
Output is correct |
34 |
Correct |
11 ms |
11944 KB |
Output is correct |
35 |
Correct |
68 ms |
15832 KB |
Output is correct |
36 |
Correct |
73 ms |
15824 KB |
Output is correct |
37 |
Correct |
73 ms |
15900 KB |
Output is correct |
38 |
Correct |
74 ms |
15876 KB |
Output is correct |
39 |
Correct |
68 ms |
15916 KB |
Output is correct |
40 |
Correct |
74 ms |
15808 KB |
Output is correct |
41 |
Correct |
74 ms |
15820 KB |
Output is correct |
42 |
Correct |
75 ms |
15876 KB |
Output is correct |
43 |
Correct |
71 ms |
15820 KB |
Output is correct |
44 |
Correct |
68 ms |
15896 KB |
Output is correct |
45 |
Correct |
77 ms |
15812 KB |
Output is correct |
46 |
Correct |
67 ms |
15900 KB |
Output is correct |
47 |
Correct |
68 ms |
15896 KB |
Output is correct |
48 |
Correct |
72 ms |
15876 KB |
Output is correct |
49 |
Correct |
73 ms |
15900 KB |
Output is correct |
50 |
Correct |
79 ms |
15896 KB |
Output is correct |
51 |
Correct |
103 ms |
15824 KB |
Output is correct |
52 |
Correct |
80 ms |
15836 KB |
Output is correct |
53 |
Correct |
87 ms |
15888 KB |
Output is correct |
54 |
Correct |
87 ms |
15896 KB |
Output is correct |
55 |
Correct |
82 ms |
15876 KB |
Output is correct |
56 |
Correct |
80 ms |
15900 KB |
Output is correct |
57 |
Correct |
74 ms |
15876 KB |
Output is correct |
58 |
Correct |
102 ms |
15868 KB |
Output is correct |
59 |
Correct |
79 ms |
15792 KB |
Output is correct |
60 |
Correct |
75 ms |
15824 KB |
Output is correct |
61 |
Correct |
12 ms |
11960 KB |
Output is correct |
62 |
Correct |
11 ms |
12024 KB |
Output is correct |
63 |
Correct |
12 ms |
12156 KB |
Output is correct |
64 |
Correct |
12 ms |
11988 KB |
Output is correct |
65 |
Correct |
48 ms |
13908 KB |
Output is correct |
66 |
Correct |
38 ms |
13376 KB |
Output is correct |
67 |
Correct |
74 ms |
15080 KB |
Output is correct |
68 |
Correct |
18 ms |
12364 KB |
Output is correct |
69 |
Correct |
12 ms |
11908 KB |
Output is correct |
70 |
Correct |
12 ms |
11948 KB |
Output is correct |
71 |
Correct |
11 ms |
11988 KB |
Output is correct |