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>
#pragma GCC ("fast-math")
using namespace std;
#define int long long
const int MOD = 1e6+3;
int n,k;
int sum[1000005];
bool verif(int poz, int cur)
{
if(cur<0 || cur>1) return 0;
if(poz+k >= n) return 1;
///a[poz+k] - a[poz] = sum[poz+1] - sum[poz]
return verif(poz+k, sum[poz+1] - sum[poz] + cur);
}
int put(int a, int exp)
{
if(exp==0)
return 1;
if(exp%2==0)
return put(a*a%MOD,exp/2);
else
return put(a*a%MOD,exp/2)*a%MOD;
}
int comb(int x, int y)
{
if(x<y) return 0;
int prod=1;
for(int i=1;i<=x;i++)
prod = prod*i%MOD;
for(int i=1;i<=y;i++)
prod = prod*put(i,MOD-2)%MOD;
for(int i=1;i<=x-y;i++)
prod = prod*put(i,MOD-2)%MOD;
return prod;
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>k;
for(int i=0;i<n-k+1;i++)
cin>>sum[i];
int cnt0=0,cnt1=0,cnt01=0;
for(int i=0;i<k;i++)
{
bool pos0 = verif(i,0);
bool pos1 = verif(i,1);
if(pos0 && pos1) cnt01++;
else if(pos0) cnt0++;
else if(pos1) cnt1++;
else {cout<<0;return 0;}
}
cout<<comb(cnt01,sum[0]-cnt1);
return 0;
}
Compilation message (stderr)
Main.cpp:2: warning: ignoring '#pragma GCC ' [-Wunknown-pragmas]
2 | #pragma GCC ("fast-math")
|
# | 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... |