Submission #986483

#TimeUsernameProblemLanguageResultExecution timeMemory
986483alexddBinaria (CCO23_day1problem1)C++17
25 / 25
107 ms13080 KiB
#include<bits/stdc++.h> 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...