# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027280 | khanhtb | Binaria (CCO23_day1problem1) | C++14 | 69 ms | 31648 KiB |
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>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e6 + 3;
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 1e6 + 1;
ll n,fac[N],invfac[N];
ll bipow(ll a, ll b){
ll ans = 1;
while(b){
if(b&1) ans = ans*a%mod;
a = a*a%mod;
b>>=1;
}
return ans;
}
void precalc(){
fac[0] = 1;
for(ll i = 1; i < N; i++) fac[i] = fac[i-1]*i%mod;
invfac[N-1] = bipow(fac[N-1],mod-2);
for(ll i = N-2; i >= 0; i--) invfac[i] = invfac[i+1]*(i+1)%mod;
}
ll C(ll k, ll n){
if(k > n || k < 0) return 0;
return ((fac[n]*invfac[k])%mod)*invfac[n-k]%mod;
}
ll k,a[N];
ll d[N];
void solve(){
cin >> n >> k;
fill(a,a+n+1,-1);
for(ll i = 1; i <= n-k+1; i++) cin >> d[i];
for(ll i = n-k; i >= 1; i--){
if(abs(d[i]-d[i+1]) > 1){
cout << 0;
return;
}
if(d[i] > d[i+1]){
if(a[i+k] == 1){
cout << 0;
return;
}
a[i] = 1;
}
else if(d[i] < d[i+1]){
if(a[i+k] == 0){
cout << 0;
return;
}
a[i] = 0;
}
else if(d[i] == d[i+1]) a[i] = a[i+k];
}
precalc();
ll cnt = 0;
ll n1 = d[1];
for(ll i = 1; i <= k; i++){
if(a[i] == -1) cnt++;
if(a[i] == 1) n1--;
}
cout << C(n1,cnt);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; i++){
solve();
cout << '\n';
}
}
Compilation message (stderr)
# | 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... |