Submission #391760

# Submission time Handle Problem Language Result Execution time Memory
391760 2021-04-19T17:10:19 Z huukhang A Huge Tower (CEOI10_tower) C++11
100 / 100
133 ms 10456 KB
// - Only when necessary :d
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fileopen(a, b) freopen(((string)a + ".inp").c_str(), "r", stdin); freopen(((string)b + ".out").c_str(), "w", stdout); 

#define ll long long
#define int long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll mod = 1e9 + 9;
const ll inf = 1e9 + 7;
const double eps = 1e-9;

int n, d;
int a[1000005];
int ans = 1;

signed main() {
	#ifdef khangorz
		fileopen("input", "output");
	#endif
	#ifndef khangorz
//		fileopen("LAH", "LAH");
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> d;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	sort(a + 1, a + n + 1);

	int p1 = 1, p2 = 1;
	for (; p1 <= n; ++p1) {
		while (p2 <= n && a[p2] - a[p1] <= d) ++p2;
		ans = (ans*(p2 - p1))%mod;
	}

	cout << ans;
	return 0;
}
# 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 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 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 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1104 KB Output is correct
2 Correct 10 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 4620 KB Output is correct
2 Correct 52 ms 4708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10456 KB Output is correct
2 Correct 133 ms 10356 KB Output is correct