#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define ll long long
#define pii pair<int,int>
#define fs first
#define sc second
const int mxn = 1e6+2;
const ll mod = 1e6+3;
ll fac[mxn],ifac[mxn];
int arr[mxn];
int val[mxn];
ll N,K;
ll pw(ll a,ll b){
ll re = 1;
while(b){
if(b&1)re = re*a%mod;
b>>=1;
a = a*a%mod;
}
return re;
}
ll inv(ll k){
return pw(k,mod-2);
}
ll C(ll a,ll b){
if(b>a)return 0;
return fac[a]*ifac[b]%mod*ifac[a-b]%mod;
}
void check(int p,int v){
int pp = p;
p = pp-K;
while(p>=0&&val[p] == -1)val[p] = v,p -= K;
p = pp+K;
while(p<N&&val[p] == -1)val[p] = v,p += K;
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
fac[0] = ifac[0] = 1;
for(int i = 1;i<mxn;i++)fac[i] = fac[i-1]*i%mod;
ifac[mxn-1] = inv(fac[mxn-1]);
for(int i = mxn-2;i>=0;i--)ifac[i] = ifac[i+1]*(i+1)%mod;
cin>>N>>K;
for(int i = 0;i<N-K+1;i++){
cin>>arr[i];
}
for(int i = 0;i<N-K+1;i++){
if(arr[i]>K){
cout<<"0\n";
return 0;
}
}
memset(val,-1,sizeof(val));
for(int i = 0;i+1<N-K+1;i++){
if(abs(arr[i]-arr[i+1]) > 1){
cout<<"0\n";
return 0;
}
if(arr[i]>arr[i+1]){
val[i] = 1,val[i+K] = 0;
}
else if(arr[i]<arr[i+1]){
val[i] = 0,val[i+K] = 1;
}
}
for(int i = 0;i<N;i++){
if(val[i] != -1)check(i,val[i]);
}
for(int i = 0;i+1<N-K+1;i++){
if(arr[i]>arr[i+1]){
if(val[i] != 1||val[i+K] != 0){
cout<<"0\n";
return 0;
}
}
else if(arr[i]<arr[i+1]){
if(val[i] != 0||val[i+K] != 1){
cout<<"0\n";
return 0;
}
}
else{
if(val[i] != val[i+K]){
cout<<"0\n";
return 0;
}
}
}
int sum = 0,cnt = 0;
for(int i = 0;i<K;i++){
if(val[i] != -1)sum += val[i];
else cnt++;
}
if(sum>arr[0]||sum+cnt<arr[0]){
cout<<"0\n";
return 0;
}
cout<<C(cnt,arr[0]-sum)<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
13 |
Correct |
11 ms |
21852 KB |
Output is correct |
14 |
Correct |
12 ms |
21848 KB |
Output is correct |
15 |
Correct |
12 ms |
21852 KB |
Output is correct |
16 |
Correct |
11 ms |
21852 KB |
Output is correct |
17 |
Correct |
12 ms |
21856 KB |
Output is correct |
18 |
Correct |
12 ms |
21852 KB |
Output is correct |
19 |
Correct |
11 ms |
21976 KB |
Output is correct |
20 |
Correct |
12 ms |
21860 KB |
Output is correct |
21 |
Correct |
12 ms |
21856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
13 |
Correct |
11 ms |
21852 KB |
Output is correct |
14 |
Correct |
12 ms |
21848 KB |
Output is correct |
15 |
Correct |
12 ms |
21852 KB |
Output is correct |
16 |
Correct |
11 ms |
21852 KB |
Output is correct |
17 |
Correct |
12 ms |
21856 KB |
Output is correct |
18 |
Correct |
12 ms |
21852 KB |
Output is correct |
19 |
Correct |
11 ms |
21976 KB |
Output is correct |
20 |
Correct |
12 ms |
21860 KB |
Output is correct |
21 |
Correct |
12 ms |
21856 KB |
Output is correct |
22 |
Correct |
11 ms |
21852 KB |
Output is correct |
23 |
Correct |
12 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
12 ms |
21852 KB |
Output is correct |
26 |
Correct |
12 ms |
21852 KB |
Output is correct |
27 |
Correct |
11 ms |
21852 KB |
Output is correct |
28 |
Correct |
12 ms |
21704 KB |
Output is correct |
29 |
Correct |
12 ms |
21860 KB |
Output is correct |
30 |
Correct |
12 ms |
21852 KB |
Output is correct |
31 |
Correct |
12 ms |
21856 KB |
Output is correct |
32 |
Correct |
12 ms |
21700 KB |
Output is correct |
33 |
Correct |
12 ms |
21852 KB |
Output is correct |
34 |
Correct |
12 ms |
21852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
13 |
Correct |
11 ms |
21852 KB |
Output is correct |
14 |
Correct |
12 ms |
21848 KB |
Output is correct |
15 |
Correct |
12 ms |
21852 KB |
Output is correct |
16 |
Correct |
11 ms |
21852 KB |
Output is correct |
17 |
Correct |
12 ms |
21856 KB |
Output is correct |
18 |
Correct |
12 ms |
21852 KB |
Output is correct |
19 |
Correct |
11 ms |
21976 KB |
Output is correct |
20 |
Correct |
12 ms |
21860 KB |
Output is correct |
21 |
Correct |
12 ms |
21856 KB |
Output is correct |
22 |
Correct |
11 ms |
21852 KB |
Output is correct |
23 |
Correct |
12 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
12 ms |
21852 KB |
Output is correct |
26 |
Correct |
12 ms |
21852 KB |
Output is correct |
27 |
Correct |
11 ms |
21852 KB |
Output is correct |
28 |
Correct |
12 ms |
21704 KB |
Output is correct |
29 |
Correct |
12 ms |
21860 KB |
Output is correct |
30 |
Correct |
12 ms |
21852 KB |
Output is correct |
31 |
Correct |
12 ms |
21856 KB |
Output is correct |
32 |
Correct |
12 ms |
21700 KB |
Output is correct |
33 |
Correct |
12 ms |
21852 KB |
Output is correct |
34 |
Correct |
12 ms |
21852 KB |
Output is correct |
35 |
Correct |
50 ms |
23748 KB |
Output is correct |
36 |
Correct |
60 ms |
23888 KB |
Output is correct |
37 |
Correct |
66 ms |
24000 KB |
Output is correct |
38 |
Correct |
56 ms |
23768 KB |
Output is correct |
39 |
Correct |
50 ms |
23728 KB |
Output is correct |
40 |
Correct |
55 ms |
23896 KB |
Output is correct |
41 |
Correct |
59 ms |
23740 KB |
Output is correct |
42 |
Correct |
54 ms |
23764 KB |
Output is correct |
43 |
Correct |
54 ms |
23740 KB |
Output is correct |
44 |
Correct |
50 ms |
23892 KB |
Output is correct |
45 |
Correct |
51 ms |
23736 KB |
Output is correct |
46 |
Correct |
49 ms |
23892 KB |
Output is correct |
47 |
Correct |
51 ms |
23892 KB |
Output is correct |
48 |
Correct |
61 ms |
23888 KB |
Output is correct |
49 |
Correct |
63 ms |
23892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
13 |
Correct |
11 ms |
21852 KB |
Output is correct |
14 |
Correct |
12 ms |
21848 KB |
Output is correct |
15 |
Correct |
12 ms |
21852 KB |
Output is correct |
16 |
Correct |
11 ms |
21852 KB |
Output is correct |
17 |
Correct |
12 ms |
21856 KB |
Output is correct |
18 |
Correct |
12 ms |
21852 KB |
Output is correct |
19 |
Correct |
11 ms |
21976 KB |
Output is correct |
20 |
Correct |
12 ms |
21860 KB |
Output is correct |
21 |
Correct |
12 ms |
21856 KB |
Output is correct |
22 |
Correct |
11 ms |
21852 KB |
Output is correct |
23 |
Correct |
12 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
12 ms |
21852 KB |
Output is correct |
26 |
Correct |
12 ms |
21852 KB |
Output is correct |
27 |
Correct |
11 ms |
21852 KB |
Output is correct |
28 |
Correct |
12 ms |
21704 KB |
Output is correct |
29 |
Correct |
12 ms |
21860 KB |
Output is correct |
30 |
Correct |
12 ms |
21852 KB |
Output is correct |
31 |
Correct |
12 ms |
21856 KB |
Output is correct |
32 |
Correct |
12 ms |
21700 KB |
Output is correct |
33 |
Correct |
12 ms |
21852 KB |
Output is correct |
34 |
Correct |
12 ms |
21852 KB |
Output is correct |
35 |
Correct |
50 ms |
23748 KB |
Output is correct |
36 |
Correct |
60 ms |
23888 KB |
Output is correct |
37 |
Correct |
66 ms |
24000 KB |
Output is correct |
38 |
Correct |
56 ms |
23768 KB |
Output is correct |
39 |
Correct |
50 ms |
23728 KB |
Output is correct |
40 |
Correct |
55 ms |
23896 KB |
Output is correct |
41 |
Correct |
59 ms |
23740 KB |
Output is correct |
42 |
Correct |
54 ms |
23764 KB |
Output is correct |
43 |
Correct |
54 ms |
23740 KB |
Output is correct |
44 |
Correct |
50 ms |
23892 KB |
Output is correct |
45 |
Correct |
51 ms |
23736 KB |
Output is correct |
46 |
Correct |
49 ms |
23892 KB |
Output is correct |
47 |
Correct |
51 ms |
23892 KB |
Output is correct |
48 |
Correct |
61 ms |
23888 KB |
Output is correct |
49 |
Correct |
63 ms |
23892 KB |
Output is correct |
50 |
Correct |
64 ms |
23888 KB |
Output is correct |
51 |
Correct |
63 ms |
23756 KB |
Output is correct |
52 |
Correct |
68 ms |
23892 KB |
Output is correct |
53 |
Correct |
77 ms |
23892 KB |
Output is correct |
54 |
Correct |
64 ms |
23892 KB |
Output is correct |
55 |
Correct |
66 ms |
23892 KB |
Output is correct |
56 |
Correct |
67 ms |
23988 KB |
Output is correct |
57 |
Correct |
68 ms |
23748 KB |
Output is correct |
58 |
Correct |
73 ms |
23744 KB |
Output is correct |
59 |
Correct |
67 ms |
23892 KB |
Output is correct |
60 |
Correct |
67 ms |
23888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
21852 KB |
Output is correct |
2 |
Correct |
12 ms |
21696 KB |
Output is correct |
3 |
Correct |
13 ms |
21848 KB |
Output is correct |
4 |
Correct |
11 ms |
21852 KB |
Output is correct |
5 |
Correct |
12 ms |
21852 KB |
Output is correct |
6 |
Correct |
12 ms |
21848 KB |
Output is correct |
7 |
Correct |
12 ms |
21852 KB |
Output is correct |
8 |
Correct |
12 ms |
21852 KB |
Output is correct |
9 |
Correct |
12 ms |
21852 KB |
Output is correct |
10 |
Correct |
12 ms |
21852 KB |
Output is correct |
11 |
Correct |
12 ms |
21704 KB |
Output is correct |
12 |
Correct |
12 ms |
21852 KB |
Output is correct |
13 |
Correct |
11 ms |
21852 KB |
Output is correct |
14 |
Correct |
12 ms |
21848 KB |
Output is correct |
15 |
Correct |
12 ms |
21852 KB |
Output is correct |
16 |
Correct |
11 ms |
21852 KB |
Output is correct |
17 |
Correct |
12 ms |
21856 KB |
Output is correct |
18 |
Correct |
12 ms |
21852 KB |
Output is correct |
19 |
Correct |
11 ms |
21976 KB |
Output is correct |
20 |
Correct |
12 ms |
21860 KB |
Output is correct |
21 |
Correct |
12 ms |
21856 KB |
Output is correct |
22 |
Correct |
11 ms |
21852 KB |
Output is correct |
23 |
Correct |
12 ms |
21852 KB |
Output is correct |
24 |
Correct |
11 ms |
21852 KB |
Output is correct |
25 |
Correct |
12 ms |
21852 KB |
Output is correct |
26 |
Correct |
12 ms |
21852 KB |
Output is correct |
27 |
Correct |
11 ms |
21852 KB |
Output is correct |
28 |
Correct |
12 ms |
21704 KB |
Output is correct |
29 |
Correct |
12 ms |
21860 KB |
Output is correct |
30 |
Correct |
12 ms |
21852 KB |
Output is correct |
31 |
Correct |
12 ms |
21856 KB |
Output is correct |
32 |
Correct |
12 ms |
21700 KB |
Output is correct |
33 |
Correct |
12 ms |
21852 KB |
Output is correct |
34 |
Correct |
12 ms |
21852 KB |
Output is correct |
35 |
Correct |
50 ms |
23748 KB |
Output is correct |
36 |
Correct |
60 ms |
23888 KB |
Output is correct |
37 |
Correct |
66 ms |
24000 KB |
Output is correct |
38 |
Correct |
56 ms |
23768 KB |
Output is correct |
39 |
Correct |
50 ms |
23728 KB |
Output is correct |
40 |
Correct |
55 ms |
23896 KB |
Output is correct |
41 |
Correct |
59 ms |
23740 KB |
Output is correct |
42 |
Correct |
54 ms |
23764 KB |
Output is correct |
43 |
Correct |
54 ms |
23740 KB |
Output is correct |
44 |
Correct |
50 ms |
23892 KB |
Output is correct |
45 |
Correct |
51 ms |
23736 KB |
Output is correct |
46 |
Correct |
49 ms |
23892 KB |
Output is correct |
47 |
Correct |
51 ms |
23892 KB |
Output is correct |
48 |
Correct |
61 ms |
23888 KB |
Output is correct |
49 |
Correct |
63 ms |
23892 KB |
Output is correct |
50 |
Correct |
64 ms |
23888 KB |
Output is correct |
51 |
Correct |
63 ms |
23756 KB |
Output is correct |
52 |
Correct |
68 ms |
23892 KB |
Output is correct |
53 |
Correct |
77 ms |
23892 KB |
Output is correct |
54 |
Correct |
64 ms |
23892 KB |
Output is correct |
55 |
Correct |
66 ms |
23892 KB |
Output is correct |
56 |
Correct |
67 ms |
23988 KB |
Output is correct |
57 |
Correct |
68 ms |
23748 KB |
Output is correct |
58 |
Correct |
73 ms |
23744 KB |
Output is correct |
59 |
Correct |
67 ms |
23892 KB |
Output is correct |
60 |
Correct |
67 ms |
23888 KB |
Output is correct |
61 |
Correct |
12 ms |
21852 KB |
Output is correct |
62 |
Correct |
12 ms |
21852 KB |
Output is correct |
63 |
Correct |
12 ms |
21852 KB |
Output is correct |
64 |
Correct |
13 ms |
21852 KB |
Output is correct |
65 |
Correct |
46 ms |
23756 KB |
Output is correct |
66 |
Correct |
36 ms |
23888 KB |
Output is correct |
67 |
Correct |
68 ms |
23892 KB |
Output is correct |
68 |
Correct |
18 ms |
21852 KB |
Output is correct |
69 |
Correct |
12 ms |
21852 KB |
Output is correct |
70 |
Correct |
13 ms |
21852 KB |
Output is correct |
71 |
Correct |
12 ms |
21852 KB |
Output is correct |