#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int long long
using namespace std;
const ll MOD = 1e9 + 9;
ll powerm(ll a,ll b,ll m) { //m-> mod
if(b==0) {
return 1;
}
ll res=powerm(a,b/2,m);
if(b%2) {
return ((res*res)%m*(a%m))%m;
}
return (res*res)%m;
}
//INVERSE -> a^(m-2) ...m -> prime
ll power(ll a,ll b) {
if(b==0) {
return 1;
}
ll res=power(a,b/2);
if(b%2==0) {
return res*res;
}
return res*res*a;
}
/*void facm(ll m) { //factorial mod precompute
fac[0]=1;
for(int i=1;i<fac.size();i++) { //name an array fac
fac[i]=((i)%m*fac[i-1])%m;
}
return;
}
ll choose(ll a,ll b,ll m) { //a choose b mod m
ll ans=((fac[a]*(powerm(fac[a-b],m-2,m)))%m*powerm(fac[b],m-2,m))%m;
return ans;
}*/
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("revegetate.in","r",stdin);
//freopen("revegetate.out","w",stdout);
int n,d;
cin>>n>>d;
vector<int>vec(n+1),t(n+1);
vec[0]=0,t[0]=0,t[1]=1;
for(int i=1;i<=n;i++) {
cin>>vec[i];
}
sort(vec.begin(),vec.end());
for(int i=2;i<=n;i++) {
int first=1,last=i,j;
while(first<=last) {
int mid=(first+last)/2;
if(vec[mid]>=vec[i]-d) {
j=mid;
last=mid-1;
} else {
first=mid+1;
}
}
t[i]=t[i-1]*(i-j+1);
}
cout<<t[n];
return 0;
}
Compilation message
tower.cpp: In function 'int main()':
tower.cpp:71:23: warning: 'j' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | t[i]=t[i-1]*(i-j+1);
| ~^~
# |
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 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't 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 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
120 ms |
10100 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |