Submission #989975

# Submission time Handle Problem Language Result Execution time Memory
989975 2024-05-29T09:34:22 Z IdanRosen A Huge Tower (CEOI10_tower) C++
100 / 100
99 ms 8528 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

#define MOD ((ll) 1e9 + 9)

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    ll n, d;
    cin >> n >> d;

    vector<ll> arr(n);
    for (auto &ref: arr) cin >> ref;

    // process the ans block by block, in increasing order of width
    std::sort(arr.begin(), arr.end());

    // for the block of the current iteration, all the previous blocks are smaller than it meaning they can all be placed above it.
    // so our new answer will at least stay the same (not decrease).

    // but, in addition, if there are some k blocks which the new block can be placed above them (its size is not much bigger than theirs),
    // then there are another curr_ans * k possibilities for the new tower

    ll ans = 1;
    for (int i = 1; i < n; i++) {
        ll curr_width = arr[i];

        ll start = 0;
        ll end = i;
        while (start < end) {
            ll mid = start + (end - start) / 2;
            if (arr[mid] + d < curr_width)
                start = mid + 1;
            else
                end = mid;
        }
        ll k = i - start; // the number of blocks which the new block can be placed above

        ans += (ans * k) % MOD;
        ans %= MOD;
    }

    cout << ans;
}
# 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 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 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 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 1 ms 604 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 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1112 KB Output is correct
2 Correct 10 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 3932 KB Output is correct
2 Correct 35 ms 3928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 8528 KB Output is correct
2 Correct 99 ms 8380 KB Output is correct