This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
_ _ __ _ _ _ _ _ _
|a ||t ||o d | |o |
| __ _| | _ | __| _ |
| __ |/_ | __ /__\ / _\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 1000000;
const int MOD = (int) 1e6 + 3;
int pwr (const int &a, const int &b) {
if (b == 0) {
return 1;
} else if (b & 1) {
return (ll) a * pwr(a, (b ^ 1)) % MOD;
} else {
int aux = pwr(a, (b >> 1));
return (ll) aux * aux % MOD;
}
}
int inv (const int &a) {
return pwr(a, MOD - 2);
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
int A[N - K + 1];
for (int i = 0; i < N - K + 1; i++) {
cin >> A[i];
}
int B[N - K + 1];
fill(B, B + N - K + 1, -1);
for (int i = N - K - 1; i >= 0; i--) {
if (A[i] < A[i + 1]) {
B[i] = 0;
} else if (A[i] > A[i + 1]) {
B[i] = 1;
} else {
B[i] = (i + K < N - K + 1 ? B[i + K] : -1);
}
}
int cnt = 0, sum = A[0];
for (int i = 0; i < K; i++) {
cnt += (B[i] == -1);
sum -= (B[i] == 1);
}
int answer = 1;
for (int i = 1; i <= cnt - sum; i++) {
answer = (ll) answer * i % MOD;
}
answer = inv(answer);
for (int i = sum + 1; i <= cnt; i++) {
answer = (ll) answer * i % MOD;
}
cout << answer << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |