Submission #433309

# Submission time Handle Problem Language Result Execution time Memory
433309 2021-06-19T13:57:11 Z jtt_ A Huge Tower (CEOI10_tower) C++17
100 / 100
141 ms 8748 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define sz(x) (int) size(x)
#define all(x) begin(x), end(x)

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,b) ROF(i,0,b)
#define each(i,x) for (auto& i : x)

template<class T> bool ckmin(T& a, T b) { return (a > b) ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, T b) { return (a < b) ? a = b, 1 : 0; }

const int INF = 1e9+5;
const int MOD = 1e9+9;
const int MX = 2e5+5;
//

//
#define M1(x) template<class T, class... U> void x(T&& a, U&&... b)
#define M2(x) (int[]) { (x forward<U>(b),0)... }
M1(pr) { cout << forward<T>(a); M2(cout << " " << ); cout << "\n"; }
M1(re) { cin >> forward<T>(a); M2(cin >> ); }

void setIO(string S = "") {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    if (size(S)) {
        freopen((S+".in").c_str(),"r",stdin);
        freopen((S+".out").c_str(),"w",stdout);
    }
}

int N,D;

int main() {
    setIO();
    re(N,D);
    vi a(N); each(i,a) re(i);
    sort(all(a));
    ll ans = 1;
    int l = 0;
    F0R(r,N) {
        while (a[r]-a[l] > D) l ++;
        // Suppose the bricks form a set {a_l ... a_r}
        // r-l+1 is the # of positions a[r] can occupy in relation to the other r-l bricks
        // It can be above each of the other bricks (r-l positions), and also below them all (1 position)
        ans = (ll)ans*(r-l+1)%MOD;
    }
    pr(ans);
}

Compilation message

tower.cpp: In function 'void setIO(std::string)':
tower.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen((S+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tower.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen((S+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 312 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 224 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 356 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 1 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 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 972 KB Output is correct
2 Correct 12 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 3700 KB Output is correct
2 Correct 61 ms 3724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 8748 KB Output is correct
2 Correct 141 ms 8132 KB Output is correct