This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/CEOI10_tower
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD ((ll)1e9 + 9)
#define MAX_N 70
vector<int> a(MAX_N);
// TODO
int main()
{
int N, D;
cin >> N >> D;
for (int i = 0; i < N; ++i)
cin >> a[i];
sort(a.begin(), a.begin() + N);
// products of factorials of all valid "subproblems"
ll ans = 1;
int i = 0, j = 0;
while (i < N && j < N)
{
if (a[j] - a[i] <= D)
{
ans = (ans % MOD) * ((j - i + 1) % MOD);
ans %= MOD;
}
if (j < N - 1 && a[j + 1] - a[i] <= D)
++j;
else if (j < N - 1 && a[j + 1] - a[j] <= D)
{
i = j;
}
else i = ++j;
}
cout << ans << '\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... |