Submission #387465

# Submission time Handle Problem Language Result Execution time Memory
387465 2021-04-08T12:54:10 Z tostes A Huge Tower (CEOI10_tower) C++17
100 / 100
141 ms 16412 KB
#include<bits/stdc++.h>
//#include<iostream>
//#include<vector>
using namespace std;
#define _ << ' ' <<
#define pb push_back
#define all(x) begin(x), end(x)
#define mp make_pair
#define f first
#define s second
#define sz(x) int((x).size())
using ll = long long;
using db = long double;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
using str = string;

vector < int > pos[30];
ll mod=1'000'000'000+9;

int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);
	//freopen("diamond.in","r",stdin);
	//freopen("diamond.out","w",stdout);
	ll n,d;
	cin >> n >> d;
	vector < ll > a(n);
	for(auto &x: a) cin >> x;
	sort(all(a));
	vector < ll > x(n);
	int i=n-1, j=n-1;
	while(j>=0 and i>=0){
		while(j-1>=0 and a[j-1]+d>=a[i]) j--;
		x[i]=i-j;
		i--;
	}
	ll ans=1;
	for(int i=0; i<n; i++){
		ans=(ans*(x[i]+1))%mod;
	}
	cout << ans << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1644 KB Output is correct
2 Correct 12 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 6764 KB Output is correct
2 Correct 53 ms 6636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 16412 KB Output is correct
2 Correct 141 ms 15468 KB Output is correct