Submission #851558

#TimeUsernameProblemLanguageResultExecution timeMemory
851558khanhphucscratchBinaria (CCO23_day1problem1)C++14
25 / 25
69 ms34640 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int a[1000001], fact[1000001], inv[1000001], color[1000001]; const int mod = 1e6+3; int power(int a, int b) { if(b == 0) return 1; int ans = power(a, b/2); ans = (ans * ans)%mod; if(b%2 == 1) ans = (ans * a)%mod; return ans; } int C(int k, int n) { if(k > n || k < 0) return 0; return (fact[n] * ((inv[k] * inv[n-k])%mod))%mod; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin>>n>>k; fact[0] = inv[0] = 1; for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i)%mod; inv[n] = power(fact[n], mod-2); for(int i = n-1; i >= 1; i--) inv[i] = (inv[i+1] * (i+1))%mod; for(int i = 1; i <= n-k+1; i++) cin>>a[i]; for(int i = 1; i <= n; i++) color[i] = 2; for(int i = n-k; i >= 1; i--){ if(abs(a[i] - a[i+1]) > 1){cout<<0; return 0;} if(a[i] == a[i+1]) color[i] = color[i+k]; else if(a[i] > a[i+1]){ if(color[i+k] == 1){cout<<0; return 0;} color[i] = 1; } else{ if(color[i+k] == 0){cout<<0; return 0;} color[i] = 0; } } /*for(int i = 1; i <= n; i++) cout<<color[i]<<" "; cout<<'\n';*/ int re = 0; for(int i = 1; i <= k; i++){a[1] -= (color[i] == 1); re += (color[i] == 2);} cout<<C(a[1], re); }
#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...