Submission #868389

# Submission time Handle Problem Language Result Execution time Memory
868389 2023-10-31T10:34:53 Z overwatch9 A Huge Tower (CEOI10_tower) C++17
100 / 100
266 ms 39824 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const int mod = 1e9 + 9;
vector <ll> dp, nums, perm;
int n, d;
ll solve(int i) {
    if (i <= 0)
        return 1;
    if (dp[i] != -1)
        return dp[i];
    int l = lower_bound(nums.begin() + 1, nums.end(), nums[i] - d) - nums.begin();
    ll ans = solve(i-1) * (i - l + 1);
    ans %= mod;
    dp[i] = ans;
    return ans;
}
int main() {
    cin >> n >> d;
    dp.resize(n+1, -1);
    nums.resize(n+1);
    perm.resize(n+1);
    perm[1] = 1;
    for (int i = 2; i <= n; i++)
        perm[i] = (perm[i-1] * i) % mod;
    for (int i = 1; i <= n; i++)
        cin >> nums[i];
    sort(nums.begin(), nums.end());
    cout << solve(n) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3640 KB Output is correct
2 Correct 25 ms 3524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 16144 KB Output is correct
2 Correct 103 ms 16404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 39420 KB Output is correct
2 Correct 266 ms 39824 KB Output is correct