Submission #553391

# Submission time Handle Problem Language Result Execution time Memory
553391 2022-04-25T17:19:55 Z Hona_Nguyen A Huge Tower (CEOI10_tower) C++17
100 / 100
135 ms 11160 KB
#include<bits/stdc++.h>
#define prob "C"
using namespace std;
const int maxn = 1e5;
const int MOD = 1e9 + 9;
int main(){
//    freopen(prob".inp","r",stdin);
//    freopen(prob".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    long long d;
    cin >> n >> d;
    vector<long long> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    long long res = 1;
    for(int i=0;i<n;i++){
        int L = 0, R = i-1, choose = -1;
        while(L <= R){
            int mid = (L + R) >> 1;
            if(a[mid] + d >= a[i]){
                choose = mid;
                R = mid - 1;
            }
            else{
                L = mid + 1;
            }
        }
        if(choose == -1) continue;
        res = res * 1ll * (i - choose + 1) % MOD;
//        cout << i << " " << choose << " " << endl;
    }
    cout << res;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 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 11 ms 1092 KB Output is correct
2 Correct 11 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 4696 KB Output is correct
2 Correct 51 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 11160 KB Output is correct
2 Correct 135 ms 10532 KB Output is correct