# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
487931 | DDTerziev04 | A Huge Tower (CEOI10_tower) | C++14 | 131 ms | 8700 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<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e6, MOD=1e9+9;
int a[MAXN];
int BinSearch(int l, int r, int x)
{
int ans;
while(l<=r)
{
int mid=l+(r-l)/2;
if(a[mid]<=x)
{
ans=mid;
r=mid-1;
}
else
{
l=mid+1;
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, d;
cin >> n >> d;
for(int i=0; i<n; i++)
{
cin >> a[i];
}
sort(a, a+n);
reverse(a, a+n);
long long ans=1;
int pr=0;
while(pr<n)
{
int idx=pr+1;
while(idx<n && a[idx-1]-a[idx]<=d)
{
idx++;
}
idx--;
long long res=1;
for(int i=pr+1; i<=idx; i++)
{
int x=BinSearch(pr, i, a[i]+d);
res=(res*(i-x+1))%MOD;
}
pr=idx+1;
ans=(ans*res)%MOD;
}
cout << ans << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |