//ᗜˬᗜ
#include<bits/stdc++.h>
#define int long long
#define vi vector <int>
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define pb emplace_back
#define fu(i, a, b) for(int i = (a); i < (b); i++)
#define fub(i, a, b) for(int i = (a); i <= (b); i++)
#define pii pair<int, int>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int lim = 1e18;
const int N = 1e6 + 3;
const int M = 1e9 + 7;
int n, k, res;
int a[N], mp[N];
int expo(int a, int b){
if(b == 0)return 1;
if(b%2 == 0)return expo((a*a)%N, b/2)%N;
return (a*expo((a*a)%N, b/2))%N;
}
int bico(int n, int k){
if(k > n or n < 0 or k < 0)return 0;
int res = 1;
fub(i, k+1, n)res = (res*i)%N;
fub(i, 1, n-k)res = (res*expo(i, N-2))%N;
return res;
}
signed main(){
fastio;
cin >> n >> k;
fub(i, 1, n-k+1)cin >> a[i];
memset(mp, -1, sizeof(mp));
fub(i, 2, n-k+1){
if(abs(a[i] - a[i-1]) > 1){
cout << 0;
return 0;
}
}
fub(i, 2, n-k+1){
if(a[i] - a[i-1] == 1){
mp[i+k-1] = 1; mp[i-1] = 0;
}
else if(a[i] - a[i-1] == -1){
mp[i+k-1] = 0; mp[i-1] = 1;
}
else mp[i+k-1] = mp[i-1];
}
for(int i = n-k; i >= 1; i--)if(a[i] == a[i+1])mp[i] = mp[i+k];
fub(i, 1, k){
res += (mp[i] == -1);
a[1] -= (mp[i] == 1);
}
cout << bico(res, a[1]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
1 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
1 ms |
8796 KB |
Output is correct |
21 |
Correct |
1 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
1 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
1 ms |
8796 KB |
Output is correct |
21 |
Correct |
1 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8852 KB |
Output is correct |
23 |
Correct |
1 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8788 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
8796 KB |
Output is correct |
29 |
Correct |
1 ms |
8796 KB |
Output is correct |
30 |
Correct |
1 ms |
8796 KB |
Output is correct |
31 |
Correct |
1 ms |
8796 KB |
Output is correct |
32 |
Correct |
2 ms |
8796 KB |
Output is correct |
33 |
Correct |
1 ms |
8796 KB |
Output is correct |
34 |
Correct |
1 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
1 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
1 ms |
8796 KB |
Output is correct |
21 |
Correct |
1 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8852 KB |
Output is correct |
23 |
Correct |
1 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8788 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
8796 KB |
Output is correct |
29 |
Correct |
1 ms |
8796 KB |
Output is correct |
30 |
Correct |
1 ms |
8796 KB |
Output is correct |
31 |
Correct |
1 ms |
8796 KB |
Output is correct |
32 |
Correct |
2 ms |
8796 KB |
Output is correct |
33 |
Correct |
1 ms |
8796 KB |
Output is correct |
34 |
Correct |
1 ms |
8796 KB |
Output is correct |
35 |
Correct |
39 ms |
17272 KB |
Output is correct |
36 |
Correct |
40 ms |
17492 KB |
Output is correct |
37 |
Correct |
48 ms |
17652 KB |
Output is correct |
38 |
Correct |
40 ms |
17764 KB |
Output is correct |
39 |
Correct |
36 ms |
17292 KB |
Output is correct |
40 |
Correct |
39 ms |
17692 KB |
Output is correct |
41 |
Correct |
46 ms |
17744 KB |
Output is correct |
42 |
Correct |
45 ms |
17308 KB |
Output is correct |
43 |
Correct |
40 ms |
17344 KB |
Output is correct |
44 |
Correct |
39 ms |
17296 KB |
Output is correct |
45 |
Correct |
40 ms |
17236 KB |
Output is correct |
46 |
Correct |
36 ms |
17236 KB |
Output is correct |
47 |
Correct |
69 ms |
17232 KB |
Output is correct |
48 |
Correct |
71 ms |
17748 KB |
Output is correct |
49 |
Correct |
41 ms |
17720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
1 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
1 ms |
8796 KB |
Output is correct |
21 |
Correct |
1 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8852 KB |
Output is correct |
23 |
Correct |
1 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8788 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
8796 KB |
Output is correct |
29 |
Correct |
1 ms |
8796 KB |
Output is correct |
30 |
Correct |
1 ms |
8796 KB |
Output is correct |
31 |
Correct |
1 ms |
8796 KB |
Output is correct |
32 |
Correct |
2 ms |
8796 KB |
Output is correct |
33 |
Correct |
1 ms |
8796 KB |
Output is correct |
34 |
Correct |
1 ms |
8796 KB |
Output is correct |
35 |
Correct |
39 ms |
17272 KB |
Output is correct |
36 |
Correct |
40 ms |
17492 KB |
Output is correct |
37 |
Correct |
48 ms |
17652 KB |
Output is correct |
38 |
Correct |
40 ms |
17764 KB |
Output is correct |
39 |
Correct |
36 ms |
17292 KB |
Output is correct |
40 |
Correct |
39 ms |
17692 KB |
Output is correct |
41 |
Correct |
46 ms |
17744 KB |
Output is correct |
42 |
Correct |
45 ms |
17308 KB |
Output is correct |
43 |
Correct |
40 ms |
17344 KB |
Output is correct |
44 |
Correct |
39 ms |
17296 KB |
Output is correct |
45 |
Correct |
40 ms |
17236 KB |
Output is correct |
46 |
Correct |
36 ms |
17236 KB |
Output is correct |
47 |
Correct |
69 ms |
17232 KB |
Output is correct |
48 |
Correct |
71 ms |
17748 KB |
Output is correct |
49 |
Correct |
41 ms |
17720 KB |
Output is correct |
50 |
Correct |
59 ms |
18880 KB |
Output is correct |
51 |
Correct |
51 ms |
18772 KB |
Output is correct |
52 |
Correct |
50 ms |
18772 KB |
Output is correct |
53 |
Correct |
52 ms |
18708 KB |
Output is correct |
54 |
Correct |
56 ms |
18772 KB |
Output is correct |
55 |
Correct |
53 ms |
18684 KB |
Output is correct |
56 |
Correct |
53 ms |
18680 KB |
Output is correct |
57 |
Correct |
54 ms |
18284 KB |
Output is correct |
58 |
Correct |
58 ms |
18788 KB |
Output is correct |
59 |
Correct |
60 ms |
18772 KB |
Output is correct |
60 |
Correct |
45 ms |
18324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8796 KB |
Output is correct |
4 |
Correct |
1 ms |
8796 KB |
Output is correct |
5 |
Correct |
1 ms |
8796 KB |
Output is correct |
6 |
Correct |
1 ms |
8796 KB |
Output is correct |
7 |
Correct |
1 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
1 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8660 KB |
Output is correct |
11 |
Correct |
1 ms |
8796 KB |
Output is correct |
12 |
Correct |
1 ms |
8704 KB |
Output is correct |
13 |
Correct |
1 ms |
8796 KB |
Output is correct |
14 |
Correct |
1 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8796 KB |
Output is correct |
16 |
Correct |
1 ms |
8796 KB |
Output is correct |
17 |
Correct |
1 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
1 ms |
8796 KB |
Output is correct |
20 |
Correct |
1 ms |
8796 KB |
Output is correct |
21 |
Correct |
1 ms |
8796 KB |
Output is correct |
22 |
Correct |
2 ms |
8852 KB |
Output is correct |
23 |
Correct |
1 ms |
8796 KB |
Output is correct |
24 |
Correct |
3 ms |
8788 KB |
Output is correct |
25 |
Correct |
3 ms |
8796 KB |
Output is correct |
26 |
Correct |
3 ms |
8796 KB |
Output is correct |
27 |
Correct |
1 ms |
8796 KB |
Output is correct |
28 |
Correct |
1 ms |
8796 KB |
Output is correct |
29 |
Correct |
1 ms |
8796 KB |
Output is correct |
30 |
Correct |
1 ms |
8796 KB |
Output is correct |
31 |
Correct |
1 ms |
8796 KB |
Output is correct |
32 |
Correct |
2 ms |
8796 KB |
Output is correct |
33 |
Correct |
1 ms |
8796 KB |
Output is correct |
34 |
Correct |
1 ms |
8796 KB |
Output is correct |
35 |
Correct |
39 ms |
17272 KB |
Output is correct |
36 |
Correct |
40 ms |
17492 KB |
Output is correct |
37 |
Correct |
48 ms |
17652 KB |
Output is correct |
38 |
Correct |
40 ms |
17764 KB |
Output is correct |
39 |
Correct |
36 ms |
17292 KB |
Output is correct |
40 |
Correct |
39 ms |
17692 KB |
Output is correct |
41 |
Correct |
46 ms |
17744 KB |
Output is correct |
42 |
Correct |
45 ms |
17308 KB |
Output is correct |
43 |
Correct |
40 ms |
17344 KB |
Output is correct |
44 |
Correct |
39 ms |
17296 KB |
Output is correct |
45 |
Correct |
40 ms |
17236 KB |
Output is correct |
46 |
Correct |
36 ms |
17236 KB |
Output is correct |
47 |
Correct |
69 ms |
17232 KB |
Output is correct |
48 |
Correct |
71 ms |
17748 KB |
Output is correct |
49 |
Correct |
41 ms |
17720 KB |
Output is correct |
50 |
Correct |
59 ms |
18880 KB |
Output is correct |
51 |
Correct |
51 ms |
18772 KB |
Output is correct |
52 |
Correct |
50 ms |
18772 KB |
Output is correct |
53 |
Correct |
52 ms |
18708 KB |
Output is correct |
54 |
Correct |
56 ms |
18772 KB |
Output is correct |
55 |
Correct |
53 ms |
18684 KB |
Output is correct |
56 |
Correct |
53 ms |
18680 KB |
Output is correct |
57 |
Correct |
54 ms |
18284 KB |
Output is correct |
58 |
Correct |
58 ms |
18788 KB |
Output is correct |
59 |
Correct |
60 ms |
18772 KB |
Output is correct |
60 |
Correct |
45 ms |
18324 KB |
Output is correct |
61 |
Correct |
74 ms |
8796 KB |
Output is correct |
62 |
Correct |
90 ms |
8828 KB |
Output is correct |
63 |
Correct |
19 ms |
8796 KB |
Output is correct |
64 |
Correct |
64 ms |
8796 KB |
Output is correct |
65 |
Correct |
57 ms |
14880 KB |
Output is correct |
66 |
Correct |
65 ms |
14468 KB |
Output is correct |
67 |
Correct |
58 ms |
17812 KB |
Output is correct |
68 |
Correct |
130 ms |
11100 KB |
Output is correct |
69 |
Correct |
2 ms |
8652 KB |
Output is correct |
70 |
Correct |
137 ms |
8796 KB |
Output is correct |
71 |
Correct |
69 ms |
8824 KB |
Output is correct |