#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
const int N = 1e6 + 5, M = 1e6 + 3, LG = 20;
int n , k , A[N] , F[N];
int pw(int a , int b){
if (a == 1 || b == 0) return 1;
int p = pw(a,b/2);
if (b&1){
return ((p*p)%M * a)%M;
}else{
return (p*p)%M;
}
}
int C(int n , int r){
if (r > n) return 0;
return (F[n] * (pw((F[r] * F[n-r])%M , M - 2)))%M;
}
void solve(){
cin >> n >> k;
for (int i=0 ; i<(n-k+1) ; i++) cin >> A[i];
for (int i=0 ; i<(n-k) ; i++){
if (abs(A[i]-A[i+1]) >= 2){
cout << 0 << endl;
return;
}
}
int ans = C(k,A[0]);
for (int i=0 ; i<min(k-1,n-k) ; i++){
if (A[i] == A[i+1]) continue;
if (A[i] > A[i+1]){
ans -= C(k-1,A[0]);
// cout << i << endl;
}else{
ans -= C(k-1,A[0]-1);
// cout << i << endl;
}
}
cout << ans << endl;
}
signed main(){
F[0] = 1;
for (int i=1 ; i<N ; i++) F[i] = (F[i-1]*i)%M;
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
// void solve(){
// cin >> n >> k;
// int ans = 0;
// for (int i=0 ; i<(n-k+1) ; i++) cin >> A[i];
// vector<int> B[k+1] = {};
// for (int i=0 ; i<(1<<k) ; i++){
// B[__builtin_popcount(i)].pb(i);
// }
// for (int i : B[A[0]]){
// int u = __builtin_popcount(i);
// string s = "";
// for (int j=0 ; j<k ; j++){
// if (i&(1<<j)){
// s += '1';
// }else{
// s += '0';
// }
// }
// bool ch = 1;
// for (int j=k ; j<n ; j++){
// if (s[j-k] == '0'){
// if (u == A[j-k+1]){
// s += '0';
// }else if (u+1 == A[j-k+1]){
// s += '1';
// u++;
// }else{
// ch = 0;
// break;
// }
// }else{
// u--;
// if (u == A[j-k+1]){
// s += '0';
// }else if (u+1 == A[j-k+1]){
// s += '1';
// u++;
// }else{
// ch = 0;
// break;
// }
// }
// }
// if (ch){
// cout << s << endl;
// ans++;
// }
// }
// cout << ans << endl;
// }
// signed main(){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int ts = 1;
// // cin >> ts;
// while(ts--){
// solve();
// }
// }
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |