Submission #986486

#TimeUsernameProblemLanguageResultExecution timeMemory
986486alexddBinaria (CCO23_day1problem1)C++17
25 / 25
61 ms13136 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 aux1=1,aux2=1; if(y<=x/2) y = x-y; for(int i=y+1;i<=x;i++) aux1 = aux1*i%MOD; for(int i=1;i<=x-y;i++) aux2 = aux2*i%MOD; return aux1*put(aux2,MOD-2)%MOD; } 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...