Submission #856619

# Submission time Handle Problem Language Result Execution time Memory
856619 2023-10-04T05:20:24 Z HanavM A Huge Tower (CEOI10_tower) C++17
100 / 100
215 ms 10504 KB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 9;

int main() {
	ll n, d; cin >> n >> d;
	vector <ll> blocks(n);
	for (int i=0;i<n;i++){
		cin >> blocks[i];
	}
	int left = 0; int right = 0;
	ll ans = 1;
	sort(begin(blocks),end(blocks));
	for (int i=1;i<n;i++){
		ll constant = blocks[i] - d;
		while (left < n){
			if (blocks[left] < constant){
				left++;
			}
			else{
				break;
			}
		}
		right ++;
		// cout <<i <<" " << left << " " << right << endl;
		if (left != right){
			ans = ans * (right - left + 1);
			ans = ans % mod;
		}
	}
	cout << ans % mod;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 17 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2396 KB Output is correct
2 Correct 86 ms 4680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 203 ms 5208 KB Output is correct
2 Correct 215 ms 10504 KB Output is correct