Submission #1027459

#TimeUsernameProblemLanguageResultExecution timeMemory
1027459cnn008Binaria (CCO23_day1problem1)C++17
25 / 25
181 ms36616 KiB
#include "bits/stdc++.h" using namespace std; #ifdef N_N_C #include "debug.h" #else #define cebug(...) "Arya" #endif #define int long long const int N=1e6+5; const int mod=1e6+3; int n,k,a[N],f[N],inv[N],b[N]; int powmod(int a, int k, int m){ int ans=1; while(k){ if(k&1) ans=(ans*a)%m; a=(a*a)%m; k/=2; } return ans; } int C(int n, int k){ if(n<k || k<0) return 0; return f[n]*inv[k]%mod*inv[n-k]%mod; } void sol(){ cin>>n>>k; for(int i=k; i<=n; i++) cin>>a[i]; memset(b,-1,sizeof(b)); for(int i=k+1; i<=n; i++){ if(a[i]==a[i-1]+1){ if(b[i-k]==1){ cout<<"0"; return; } b[i-k]=0; b[i]=1; }else if(a[i]==a[i-1]){ if(b[i-k]==1) b[i]=1; if(b[i-k]==0) b[i]=0; }else if(a[i]==a[i-1]-1){ if(b[i-k]==0){ cout<<"0"; return; } b[i-k]=1; b[i]=0; }else{ cout<<"0"; return; } } for(int i=n; i>=k+1; i--) if(a[i]==a[i-1]) b[i]=b[i-k]=max(b[i],b[i-k]); int sz=0,cnt=0; for(int i=1; i<=k; i++){ if(b[i]==-1) sz++; if(b[i]==1) cnt++; } cout<<C(sz,a[k]-cnt); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); f[0]=1; for(int i=1; i<N; i++) f[i]=(f[i-1]*i)%mod; inv[0]=1; for(int i=1; i<N; i++) inv[i]=powmod(f[i],mod-2,mod); int tt=1; //cin>>tt; while(tt--){ sol(); } cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; 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...