# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393909 | tcmmichaelb139 | A Huge Tower (CEOI10_tower) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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
*/