#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e6 + 1;
const int N = 1e6 + 3;
const int INF = 1e18;
int f[maxn], inf[maxn];
ll fpow(ll a, ll b){
ll ret = 1;
while(b){
if(b & 1) ret = ret * a % N;
a = a * a % N;
b >>= 1;
}
return ret;
}
ll inv(ll a){ return fpow(a, N - 2);}
void precal(){
f[0] = 1;
for(int i = 1; i < maxn; i++) f[i] = f[i - 1] * i % N;
inf[maxn - 1] = inv(f[maxn - 1]);
for(int i = maxn - 2; i >= 0; i--) inf[i] = inf[i + 1] * (i + 1) % N;
}
ll binom(ll n, ll k){
if(n < k) return 0;
return f[n] * inf[k] % N * inf[n - k] % N;
}
signed main(void){
fastio;
precal();
int n, k;
cin>>n>>k;
vector<int> s(n - k + 1);
int bad = 0;
for(auto &x : s){
cin>>x;
if(x > k) bad = 1;
}
for(int i = 0; i < s.size() - 1; i++){
if(abs(s[i + 1] - s[i]) >= 2) bad = 1;
}
if(bad){
cout<<0<<"\n";
return 0;
}
int fr = k, cnt = 0;
for(int i = 0; i < k; i++){
int nd = -1;
for(int j = i; j + 1 < s.size(); j += k){
if(s[j + 1] - s[j] == 0) continue;
if(s[j + 1] - s[j] == 1){
nd = 0;
break;
}
if(s[j + 1] - s[j] == -1){
nd = 1;
break;
}
}
if(nd != -1) fr--, cnt += nd;
}
cout<<binom(fr, s[0] - cnt)<<"\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:53:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 0; i < s.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
Main.cpp:63:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j = i; j + 1 < s.size(); j += k){
| ~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
13 |
Correct |
11 ms |
15964 KB |
Output is correct |
14 |
Correct |
11 ms |
16088 KB |
Output is correct |
15 |
Correct |
11 ms |
15964 KB |
Output is correct |
16 |
Correct |
11 ms |
15912 KB |
Output is correct |
17 |
Correct |
11 ms |
16092 KB |
Output is correct |
18 |
Correct |
11 ms |
15964 KB |
Output is correct |
19 |
Correct |
11 ms |
16332 KB |
Output is correct |
20 |
Correct |
11 ms |
15964 KB |
Output is correct |
21 |
Correct |
11 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
13 |
Correct |
11 ms |
15964 KB |
Output is correct |
14 |
Correct |
11 ms |
16088 KB |
Output is correct |
15 |
Correct |
11 ms |
15964 KB |
Output is correct |
16 |
Correct |
11 ms |
15912 KB |
Output is correct |
17 |
Correct |
11 ms |
16092 KB |
Output is correct |
18 |
Correct |
11 ms |
15964 KB |
Output is correct |
19 |
Correct |
11 ms |
16332 KB |
Output is correct |
20 |
Correct |
11 ms |
15964 KB |
Output is correct |
21 |
Correct |
11 ms |
15964 KB |
Output is correct |
22 |
Correct |
11 ms |
15960 KB |
Output is correct |
23 |
Correct |
11 ms |
15920 KB |
Output is correct |
24 |
Correct |
11 ms |
15964 KB |
Output is correct |
25 |
Correct |
12 ms |
16080 KB |
Output is correct |
26 |
Correct |
11 ms |
15964 KB |
Output is correct |
27 |
Correct |
11 ms |
15964 KB |
Output is correct |
28 |
Correct |
11 ms |
15964 KB |
Output is correct |
29 |
Correct |
11 ms |
15964 KB |
Output is correct |
30 |
Correct |
11 ms |
15964 KB |
Output is correct |
31 |
Correct |
11 ms |
15912 KB |
Output is correct |
32 |
Correct |
11 ms |
15964 KB |
Output is correct |
33 |
Correct |
11 ms |
16232 KB |
Output is correct |
34 |
Correct |
11 ms |
16112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
13 |
Correct |
11 ms |
15964 KB |
Output is correct |
14 |
Correct |
11 ms |
16088 KB |
Output is correct |
15 |
Correct |
11 ms |
15964 KB |
Output is correct |
16 |
Correct |
11 ms |
15912 KB |
Output is correct |
17 |
Correct |
11 ms |
16092 KB |
Output is correct |
18 |
Correct |
11 ms |
15964 KB |
Output is correct |
19 |
Correct |
11 ms |
16332 KB |
Output is correct |
20 |
Correct |
11 ms |
15964 KB |
Output is correct |
21 |
Correct |
11 ms |
15964 KB |
Output is correct |
22 |
Correct |
11 ms |
15960 KB |
Output is correct |
23 |
Correct |
11 ms |
15920 KB |
Output is correct |
24 |
Correct |
11 ms |
15964 KB |
Output is correct |
25 |
Correct |
12 ms |
16080 KB |
Output is correct |
26 |
Correct |
11 ms |
15964 KB |
Output is correct |
27 |
Correct |
11 ms |
15964 KB |
Output is correct |
28 |
Correct |
11 ms |
15964 KB |
Output is correct |
29 |
Correct |
11 ms |
15964 KB |
Output is correct |
30 |
Correct |
11 ms |
15964 KB |
Output is correct |
31 |
Correct |
11 ms |
15912 KB |
Output is correct |
32 |
Correct |
11 ms |
15964 KB |
Output is correct |
33 |
Correct |
11 ms |
16232 KB |
Output is correct |
34 |
Correct |
11 ms |
16112 KB |
Output is correct |
35 |
Correct |
52 ms |
25724 KB |
Output is correct |
36 |
Correct |
54 ms |
26448 KB |
Output is correct |
37 |
Correct |
57 ms |
26704 KB |
Output is correct |
38 |
Correct |
60 ms |
26620 KB |
Output is correct |
39 |
Correct |
52 ms |
25844 KB |
Output is correct |
40 |
Correct |
55 ms |
26708 KB |
Output is correct |
41 |
Correct |
55 ms |
26868 KB |
Output is correct |
42 |
Correct |
52 ms |
25680 KB |
Output is correct |
43 |
Correct |
58 ms |
25860 KB |
Output is correct |
44 |
Correct |
56 ms |
25684 KB |
Output is correct |
45 |
Correct |
47 ms |
25684 KB |
Output is correct |
46 |
Correct |
49 ms |
25684 KB |
Output is correct |
47 |
Correct |
55 ms |
25684 KB |
Output is correct |
48 |
Correct |
57 ms |
26716 KB |
Output is correct |
49 |
Correct |
55 ms |
26616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
13 |
Correct |
11 ms |
15964 KB |
Output is correct |
14 |
Correct |
11 ms |
16088 KB |
Output is correct |
15 |
Correct |
11 ms |
15964 KB |
Output is correct |
16 |
Correct |
11 ms |
15912 KB |
Output is correct |
17 |
Correct |
11 ms |
16092 KB |
Output is correct |
18 |
Correct |
11 ms |
15964 KB |
Output is correct |
19 |
Correct |
11 ms |
16332 KB |
Output is correct |
20 |
Correct |
11 ms |
15964 KB |
Output is correct |
21 |
Correct |
11 ms |
15964 KB |
Output is correct |
22 |
Correct |
11 ms |
15960 KB |
Output is correct |
23 |
Correct |
11 ms |
15920 KB |
Output is correct |
24 |
Correct |
11 ms |
15964 KB |
Output is correct |
25 |
Correct |
12 ms |
16080 KB |
Output is correct |
26 |
Correct |
11 ms |
15964 KB |
Output is correct |
27 |
Correct |
11 ms |
15964 KB |
Output is correct |
28 |
Correct |
11 ms |
15964 KB |
Output is correct |
29 |
Correct |
11 ms |
15964 KB |
Output is correct |
30 |
Correct |
11 ms |
15964 KB |
Output is correct |
31 |
Correct |
11 ms |
15912 KB |
Output is correct |
32 |
Correct |
11 ms |
15964 KB |
Output is correct |
33 |
Correct |
11 ms |
16232 KB |
Output is correct |
34 |
Correct |
11 ms |
16112 KB |
Output is correct |
35 |
Correct |
52 ms |
25724 KB |
Output is correct |
36 |
Correct |
54 ms |
26448 KB |
Output is correct |
37 |
Correct |
57 ms |
26704 KB |
Output is correct |
38 |
Correct |
60 ms |
26620 KB |
Output is correct |
39 |
Correct |
52 ms |
25844 KB |
Output is correct |
40 |
Correct |
55 ms |
26708 KB |
Output is correct |
41 |
Correct |
55 ms |
26868 KB |
Output is correct |
42 |
Correct |
52 ms |
25680 KB |
Output is correct |
43 |
Correct |
58 ms |
25860 KB |
Output is correct |
44 |
Correct |
56 ms |
25684 KB |
Output is correct |
45 |
Correct |
47 ms |
25684 KB |
Output is correct |
46 |
Correct |
49 ms |
25684 KB |
Output is correct |
47 |
Correct |
55 ms |
25684 KB |
Output is correct |
48 |
Correct |
57 ms |
26716 KB |
Output is correct |
49 |
Correct |
55 ms |
26616 KB |
Output is correct |
50 |
Correct |
66 ms |
28756 KB |
Output is correct |
51 |
Correct |
65 ms |
28776 KB |
Output is correct |
52 |
Correct |
69 ms |
28752 KB |
Output is correct |
53 |
Correct |
66 ms |
28752 KB |
Output is correct |
54 |
Correct |
64 ms |
28756 KB |
Output is correct |
55 |
Correct |
66 ms |
28760 KB |
Output is correct |
56 |
Correct |
67 ms |
28764 KB |
Output is correct |
57 |
Correct |
63 ms |
28244 KB |
Output is correct |
58 |
Correct |
65 ms |
29008 KB |
Output is correct |
59 |
Correct |
64 ms |
28764 KB |
Output is correct |
60 |
Correct |
59 ms |
27732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15960 KB |
Output is correct |
2 |
Correct |
12 ms |
15960 KB |
Output is correct |
3 |
Correct |
12 ms |
15964 KB |
Output is correct |
4 |
Correct |
11 ms |
15964 KB |
Output is correct |
5 |
Correct |
11 ms |
15960 KB |
Output is correct |
6 |
Correct |
11 ms |
16080 KB |
Output is correct |
7 |
Correct |
11 ms |
15964 KB |
Output is correct |
8 |
Correct |
12 ms |
15964 KB |
Output is correct |
9 |
Correct |
12 ms |
15928 KB |
Output is correct |
10 |
Correct |
11 ms |
15964 KB |
Output is correct |
11 |
Correct |
11 ms |
16088 KB |
Output is correct |
12 |
Correct |
11 ms |
15964 KB |
Output is correct |
13 |
Correct |
11 ms |
15964 KB |
Output is correct |
14 |
Correct |
11 ms |
16088 KB |
Output is correct |
15 |
Correct |
11 ms |
15964 KB |
Output is correct |
16 |
Correct |
11 ms |
15912 KB |
Output is correct |
17 |
Correct |
11 ms |
16092 KB |
Output is correct |
18 |
Correct |
11 ms |
15964 KB |
Output is correct |
19 |
Correct |
11 ms |
16332 KB |
Output is correct |
20 |
Correct |
11 ms |
15964 KB |
Output is correct |
21 |
Correct |
11 ms |
15964 KB |
Output is correct |
22 |
Correct |
11 ms |
15960 KB |
Output is correct |
23 |
Correct |
11 ms |
15920 KB |
Output is correct |
24 |
Correct |
11 ms |
15964 KB |
Output is correct |
25 |
Correct |
12 ms |
16080 KB |
Output is correct |
26 |
Correct |
11 ms |
15964 KB |
Output is correct |
27 |
Correct |
11 ms |
15964 KB |
Output is correct |
28 |
Correct |
11 ms |
15964 KB |
Output is correct |
29 |
Correct |
11 ms |
15964 KB |
Output is correct |
30 |
Correct |
11 ms |
15964 KB |
Output is correct |
31 |
Correct |
11 ms |
15912 KB |
Output is correct |
32 |
Correct |
11 ms |
15964 KB |
Output is correct |
33 |
Correct |
11 ms |
16232 KB |
Output is correct |
34 |
Correct |
11 ms |
16112 KB |
Output is correct |
35 |
Correct |
52 ms |
25724 KB |
Output is correct |
36 |
Correct |
54 ms |
26448 KB |
Output is correct |
37 |
Correct |
57 ms |
26704 KB |
Output is correct |
38 |
Correct |
60 ms |
26620 KB |
Output is correct |
39 |
Correct |
52 ms |
25844 KB |
Output is correct |
40 |
Correct |
55 ms |
26708 KB |
Output is correct |
41 |
Correct |
55 ms |
26868 KB |
Output is correct |
42 |
Correct |
52 ms |
25680 KB |
Output is correct |
43 |
Correct |
58 ms |
25860 KB |
Output is correct |
44 |
Correct |
56 ms |
25684 KB |
Output is correct |
45 |
Correct |
47 ms |
25684 KB |
Output is correct |
46 |
Correct |
49 ms |
25684 KB |
Output is correct |
47 |
Correct |
55 ms |
25684 KB |
Output is correct |
48 |
Correct |
57 ms |
26716 KB |
Output is correct |
49 |
Correct |
55 ms |
26616 KB |
Output is correct |
50 |
Correct |
66 ms |
28756 KB |
Output is correct |
51 |
Correct |
65 ms |
28776 KB |
Output is correct |
52 |
Correct |
69 ms |
28752 KB |
Output is correct |
53 |
Correct |
66 ms |
28752 KB |
Output is correct |
54 |
Correct |
64 ms |
28756 KB |
Output is correct |
55 |
Correct |
66 ms |
28760 KB |
Output is correct |
56 |
Correct |
67 ms |
28764 KB |
Output is correct |
57 |
Correct |
63 ms |
28244 KB |
Output is correct |
58 |
Correct |
65 ms |
29008 KB |
Output is correct |
59 |
Correct |
64 ms |
28764 KB |
Output is correct |
60 |
Correct |
59 ms |
27732 KB |
Output is correct |
61 |
Correct |
13 ms |
15960 KB |
Output is correct |
62 |
Correct |
13 ms |
16220 KB |
Output is correct |
63 |
Correct |
12 ms |
15964 KB |
Output is correct |
64 |
Correct |
12 ms |
15964 KB |
Output is correct |
65 |
Correct |
45 ms |
23376 KB |
Output is correct |
66 |
Correct |
34 ms |
21072 KB |
Output is correct |
67 |
Correct |
65 ms |
27728 KB |
Output is correct |
68 |
Correct |
16 ms |
17244 KB |
Output is correct |
69 |
Correct |
12 ms |
15916 KB |
Output is correct |
70 |
Correct |
12 ms |
15960 KB |
Output is correct |
71 |
Correct |
12 ms |
15924 KB |
Output is correct |