This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e6+3;
ll rev(ll x){
ll r = 1,p=mod-2;
while(p){
if(p&1) r = r*x%mod;
x=x*x%mod;
p>>=1;
}
return r;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n,k;
cin >> n >> k;
vector<ll> a(n-k+1);
for(ll &i : a) cin >> i;
vector<ll> b(n,-1);
for(ll i = 1;i<n-k+1;i++){
if (a[i]<a[i-1]){
b[i-1] = 1;
b[i+k-1] = 0;
}else if (a[i]>a[i-1]){
b[i-1] = 0;
b[i+k-1] = 1;
}else{
}
}
for(ll i = n-1;i>=k;i--){
if (b[i]!=-1&&b[i-k]==-1) b[i-k] = b[i];
}
ll c1= 0,c0=0;
for(ll i = 0;i<k;i++){
c1 += b[i]==1;
c0 += b[i]==0;
}
ll tot = k-c1-c0;
ll w = a[0]-c1;
ll ans = 1;
for(ll i = 1;i<=w;i++){
ans = ans*rev(i)%mod*(tot-i+1)%mod;
}
cout << ans << "\n";
}
# | 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... |