Submission #475607

# Submission time Handle Problem Language Result Execution time Memory
475607 2021-09-23T10:10:33 Z XII A Huge Tower (CEOI10_tower) C++17
100 / 100
128 ms 8740 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define ALL(x) (x).begin(), (x).end()

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORU(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define IOS cin.tie(0)->sync_with_stdio(false);
#define PROB "CEOI10_tower"
void Fi(){
    if(fopen(PROB".in", "r")){
        freopen(PROB".in", "r", stdin);
        freopen(PROB".out", "w", stdout);
    }
}

const int MOD = 1e9 + 9;

int n, d;
vector<int> a;

void enter(){
    cin >> n >> d;
    a.resize(n);
    for(int &x: a) cin >> x;
    sort(ALL(a));
}

void solve(){
    int ans = 1;
    for(int l = 0, r = 0; r < n; ++r){
        while(a[r] - a[l] > d) ++l;
        ans = (1LL * ans * (r - l + 1)) % MOD;
    }
    cout << ans;
}

int main(){
    IOS;
    Fi();
    enter();
    solve();
    return 0;
}

Compilation message

tower.cpp: In function 'void Fi()':
tower.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(PROB".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
tower.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(PROB".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 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 1 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 1 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 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 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 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 972 KB Output is correct
2 Correct 11 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 3712 KB Output is correct
2 Correct 55 ms 3728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 8740 KB Output is correct
2 Correct 128 ms 8108 KB Output is correct