답안 #468510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468510 2021-08-28T15:49:12 Z tphuc2908 A Huge Tower (CEOI10_tower) C++14
100 / 100
138 ms 13044 KB
#include<bits/stdc++.h>

using namespace std;
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define repi(i,x,y) for(int i = x; i >= y; --i)
#define ci(x) int x; cin>> x
#define TC(t) ci(t); while(t--)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define cii(x, y) ci(x); ci(y)
#define ciii(x, y, z) ci(x); ci(y); ci(z)
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
const int N = 1e6 + 5;
const int mod = 1e9+9;
const int inf = 1e9 + 5;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

void readfile(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("text.inp", "r", stdin);
    #endif // ONLINE_JUDGE
//    freopen("truth.in", "r", stdin);
//    freopen("truth.out", "w", stdout);
}

int n, d;
int a[N];
ll dp[N];

void inp(){
    cin >> n >> d;
    rep(i,1,n) cin >> a[i];
    sort(a + 1, a + n + 1, greater<int>());
}

void process(){
    int j = 1;
    dp[0] = 1;
    rep(i,1,n){
        while(a[j]-a[i] > d)
            ++j;
        dp[i] = (dp[i-1]*(i-j+1))%mod;
    }
    cout << dp[n];
}

int main() {
   // readfile();
    ios_base::sync_with_stdio(0); cin.tie(0);
    inp();
    process();
    return 0;
}

Compilation message

tower.cpp: In function 'void readfile()':
tower.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen("text.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 812 KB Output is correct
2 Correct 12 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 3132 KB Output is correct
2 Correct 56 ms 5700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 7588 KB Output is correct
2 Correct 138 ms 13044 KB Output is correct