Submission #346591

# Submission time Handle Problem Language Result Execution time Memory
346591 2021-01-10T09:08:13 Z Ca7Ac1 A Huge Tower (CEOI10_tower) C++17
100 / 100
138 ms 15468 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

#define ll signed long long

using namespace std;

const ll MOD = 1e9 + 9;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    //freopen("tower.in", "r", stdin);

    ll N;
    ll D;
    cin >> N >> D;

    vector<ll> blocks(N, 0);
    for (ll i = 0; i < N; i++)
    {
        cin >> blocks[i];
    }

    sort(blocks.begin(), blocks.end(), greater<ll>());

    vector<ll> place(N, 1);
    ll j = 0;
    for (ll i = 0; i < N; i++)
    {
        while (j < N && blocks[i] - blocks[j] <= D)
        {
            j++;
        }

        place[i] = j - i;
    }

    ll sol = 1;
    for (ll i = N - 1; i >= 0; i--)
    {
        sol *= place[i] % MOD;
        sol %= MOD;
    }

    cout << (sol % MOD);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1132 KB Output is correct
2 Correct 11 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 4332 KB Output is correct
2 Correct 52 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 10092 KB Output is correct
2 Correct 138 ms 15468 KB Output is correct