Submission #393909

# Submission time Handle Problem Language Result Execution time Memory
393909 2021-04-24T21:18:04 Z tcmmichaelb139 A Huge Tower (CEOI10_tower) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define vc vector
#define pb push_back
#define pf push_front
#define rsz resize
#define sz size
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define ub upper_bound
#define lb lower_bound

#define f first
#define s second
#define mp make_pair

#define ln length
#define IMX INT_MAX
#define IMN INT_MIN

void IO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    if (s.length()) {
        freopen((s+".in").c_str(),"r",stdin);
        freopen((s+".out").c_str(),"w",stdout);
    }
}

int main() {
    IO("");

    int n, d;
    cin >> n >> d;
    vi v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(all(v));
    int r = 0, ans = 1;
    for (int l = 0; l < n; l++) {
        while (r < n-1 && v[r+1]-v[l] <= d) r++;
        int k = r-l+1;
        sol = (sol*1LL*k)%((int)1e9+9);
    }
    cout << sol << '\n';
}

/* Stuff to look for
 * int overflow, array bounds
 * special cases (n=1)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

Compilation message

tower.cpp: In function 'int main()':
tower.cpp:61:9: error: 'sol' was not declared in this scope
   61 |         sol = (sol*1LL*k)%((int)1e9+9);
      |         ^~~
tower.cpp:63:13: error: 'sol' was not declared in this scope
   63 |     cout << sol << '\n';
      |             ^~~
tower.cpp:57:16: warning: unused variable 'ans' [-Wunused-variable]
   57 |     int r = 0, ans = 1;
      |                ^~~
tower.cpp: In function 'void IO(std::string)':
tower.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   44 |         freopen((s+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tower.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   45 |         freopen((s+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~