Submission #513902

# Submission time Handle Problem Language Result Execution time Memory
513902 2022-01-17T23:23:39 Z heroescharge A Huge Tower (CEOI10_tower) C++14
100 / 100
267 ms 10632 KB
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

int N, D;

int f(int arr[]) {
    int p1loc = 0;
    int p1val = 0;
    int p2loc = 0;

    int vals[N];

    while (p2loc < N) {
        while (arr[p1loc] <= arr[p2loc] + D && p1loc < N) {
            p1loc++;
            p1val++;
        }
        vals[p2loc] = p1val;
        p2loc++;
        p1val--;
    }

    long long int prod = 1;
    int M = 1000000009;
    long long int p;
    for (int i = 0; i < N; i++) {
        p = prod * (vals[i] % M);
        prod  = p % M;
    }

    return prod;
}

int main() {
    cin >> N  >> D;
    int arr[N];
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    sort(arr, arr + N);
    cout << f(arr);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 600 KB Output is correct
2 Correct 32 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 2132 KB Output is correct
2 Correct 108 ms 4676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 5116 KB Output is correct
2 Correct 267 ms 10632 KB Output is correct