#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e6+3;
const int N=1e6+11;
int n, k, a[N], ned[N], f[N];
int po(int a, int b)
{
int r=1;
while(b)
{
if(b&1) r=r*a%mod;
b/=2;
a=a*a%mod;
}
return r%mod;
}
void sol()
{
cin >> n >> k;
for(int i=1;i<=n-k+1;i++) cin >> a[i];
for(int i=1;i<=n;i++) ned[i]=-1;
for(int i=n-k;i>=1;i--)
{
if(abs(a[i]-a[i+1])>=2)
{
cout << 0;
return;
}
if(a[i]>a[i+1])
{
if(ned[i+k]==1)
{
cout << 0;
return;
}
ned[i]=1;
}
else if(a[i]<a[i+1])
{
if(ned[i+k]==0)
{
cout << 0;
return;
}
ned[i]=0;
}
else if(a[i]==a[i+1]) ned[i]=ned[i+k];
}
int s1=a[1], s2=0;
for(int i=1;i<=k;i++)
{
if(ned[i]==1) s1--;
else if(ned[i]==-1) s2++;
}
f[0]=1;
for(int i=1;i<=k;i++) f[i]=f[i-1]*i%mod;
if(s1>s2) cout << 0;
else cout << f[s2]*po(f[s1], mod-2)%mod*po(f[s2-s1], mod-2)%mod;
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
35 ms |
18004 KB |
Output is correct |
36 |
Correct |
41 ms |
18516 KB |
Output is correct |
37 |
Correct |
42 ms |
18896 KB |
Output is correct |
38 |
Correct |
48 ms |
19028 KB |
Output is correct |
39 |
Correct |
35 ms |
18080 KB |
Output is correct |
40 |
Correct |
41 ms |
19024 KB |
Output is correct |
41 |
Correct |
49 ms |
19028 KB |
Output is correct |
42 |
Correct |
38 ms |
17908 KB |
Output is correct |
43 |
Correct |
41 ms |
17956 KB |
Output is correct |
44 |
Correct |
38 ms |
18012 KB |
Output is correct |
45 |
Correct |
36 ms |
17900 KB |
Output is correct |
46 |
Correct |
36 ms |
17880 KB |
Output is correct |
47 |
Correct |
37 ms |
17976 KB |
Output is correct |
48 |
Correct |
42 ms |
18816 KB |
Output is correct |
49 |
Correct |
41 ms |
18972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
35 ms |
18004 KB |
Output is correct |
36 |
Correct |
41 ms |
18516 KB |
Output is correct |
37 |
Correct |
42 ms |
18896 KB |
Output is correct |
38 |
Correct |
48 ms |
19028 KB |
Output is correct |
39 |
Correct |
35 ms |
18080 KB |
Output is correct |
40 |
Correct |
41 ms |
19024 KB |
Output is correct |
41 |
Correct |
49 ms |
19028 KB |
Output is correct |
42 |
Correct |
38 ms |
17908 KB |
Output is correct |
43 |
Correct |
41 ms |
17956 KB |
Output is correct |
44 |
Correct |
38 ms |
18012 KB |
Output is correct |
45 |
Correct |
36 ms |
17900 KB |
Output is correct |
46 |
Correct |
36 ms |
17880 KB |
Output is correct |
47 |
Correct |
37 ms |
17976 KB |
Output is correct |
48 |
Correct |
42 ms |
18816 KB |
Output is correct |
49 |
Correct |
41 ms |
18972 KB |
Output is correct |
50 |
Correct |
51 ms |
20944 KB |
Output is correct |
51 |
Correct |
51 ms |
20888 KB |
Output is correct |
52 |
Correct |
59 ms |
20952 KB |
Output is correct |
53 |
Correct |
52 ms |
20820 KB |
Output is correct |
54 |
Correct |
49 ms |
20952 KB |
Output is correct |
55 |
Correct |
50 ms |
20820 KB |
Output is correct |
56 |
Correct |
49 ms |
20884 KB |
Output is correct |
57 |
Correct |
46 ms |
19816 KB |
Output is correct |
58 |
Correct |
50 ms |
20816 KB |
Output is correct |
59 |
Correct |
50 ms |
20816 KB |
Output is correct |
60 |
Correct |
46 ms |
19792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
35 ms |
18004 KB |
Output is correct |
36 |
Correct |
41 ms |
18516 KB |
Output is correct |
37 |
Correct |
42 ms |
18896 KB |
Output is correct |
38 |
Correct |
48 ms |
19028 KB |
Output is correct |
39 |
Correct |
35 ms |
18080 KB |
Output is correct |
40 |
Correct |
41 ms |
19024 KB |
Output is correct |
41 |
Correct |
49 ms |
19028 KB |
Output is correct |
42 |
Correct |
38 ms |
17908 KB |
Output is correct |
43 |
Correct |
41 ms |
17956 KB |
Output is correct |
44 |
Correct |
38 ms |
18012 KB |
Output is correct |
45 |
Correct |
36 ms |
17900 KB |
Output is correct |
46 |
Correct |
36 ms |
17880 KB |
Output is correct |
47 |
Correct |
37 ms |
17976 KB |
Output is correct |
48 |
Correct |
42 ms |
18816 KB |
Output is correct |
49 |
Correct |
41 ms |
18972 KB |
Output is correct |
50 |
Correct |
51 ms |
20944 KB |
Output is correct |
51 |
Correct |
51 ms |
20888 KB |
Output is correct |
52 |
Correct |
59 ms |
20952 KB |
Output is correct |
53 |
Correct |
52 ms |
20820 KB |
Output is correct |
54 |
Correct |
49 ms |
20952 KB |
Output is correct |
55 |
Correct |
50 ms |
20820 KB |
Output is correct |
56 |
Correct |
49 ms |
20884 KB |
Output is correct |
57 |
Correct |
46 ms |
19816 KB |
Output is correct |
58 |
Correct |
50 ms |
20816 KB |
Output is correct |
59 |
Correct |
50 ms |
20816 KB |
Output is correct |
60 |
Correct |
46 ms |
19792 KB |
Output is correct |
61 |
Correct |
11 ms |
15964 KB |
Output is correct |
62 |
Correct |
10 ms |
15964 KB |
Output is correct |
63 |
Correct |
14 ms |
15920 KB |
Output is correct |
64 |
Correct |
11 ms |
15960 KB |
Output is correct |
65 |
Correct |
35 ms |
19540 KB |
Output is correct |
66 |
Correct |
29 ms |
18428 KB |
Output is correct |
67 |
Correct |
51 ms |
21536 KB |
Output is correct |
68 |
Correct |
14 ms |
16476 KB |
Output is correct |
69 |
Correct |
11 ms |
15964 KB |
Output is correct |
70 |
Correct |
11 ms |
15964 KB |
Output is correct |
71 |
Correct |
11 ms |
16060 KB |
Output is correct |