Submission #1037073

#TimeUsernameProblemLanguageResultExecution timeMemory
1037073fryingducBinaria (CCO23_day1problem1)C++17
0 / 25
116 ms12936 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 1e6 + 6; const int mod = 1e6 + 3; int n, k; int a[maxn], force[maxn]; bool check[maxn]; int fact[maxn], inv[maxn]; int power(int a, int b) { if(b == 0) return 1; int ans = power(a, b / 2); ans = (1ll * ans * ans % mod); if(b & 1) return 1ll * ans * a % mod; return ans; } int C(int n, int k) { if(k > n) return 0; return 1ll * fact[n] * inv[n - k] % mod * inv[k] % mod; } void solve() { cin >> n >> k; for(int i = 1; i <= n - k + 1; ++i) { cin >> a[i]; } fill(force, force + n + 1, -1); for(int i = 2, j = k + 1; i <= n - k + 1; ++i, ++j) { if(a[i] > a[i - 1]) { force[j] = 1, force[j - k] = 0; } else if(a[i] < a[i - 1]) { force[j - k] = 1, force[j] = 0; } } int cnt = 0; for(int i = 1; i <= k; ++i) { if(force[i] == -1) ++cnt; else { a[1] -= force[i]; } } cout << C(cnt, a[1]); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); fact[0] = inv[0] = 1; for(int i = 1; i < maxn; ++i) { fact[i] = 1ll * fact[i - 1] * i % mod; inv[i] = power(fact[i], mod - 2); } solve(); 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...