// https://oj.uz/problem/view/CEOI10_tower
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 9;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
ll d;
cin >> n >> d;
vector<ll> v (n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
vector<ll> comp (n, 0);
int cur = 1;
for (int i = 0; i < n; i++) {
int cnt = 0;
cur = max(cur, i + 1);
while (cur < n && v[cur] <= v[i] + d) {
cnt++;
cur++;
}
if (i > 0) comp[i] = max(0LL, comp[i-1] - 1);
comp[i] += cnt;
}
ll sol = 1;
for (int i = n-2; i >= 0; i--) {
ll x = 1 + comp[i];
x = x % M;
sol = (sol * x) % M;
}
cout << sol << "\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... |
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |