///YOU WILL MAKE IT
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+4;
long long MOD=1e9+9;
long long memo[21][1<<20];
int y[N],n,d,p;
long long dp(int i,int j){
// cout<<i<<" "<<j<<" "<<__builtin_popcount(j)<<endl;
if(__builtin_popcount(j)==n-1){
return 1;
}
if(memo[i][j]!=-1)
return memo[i][j];
memo[i][j]=0;
for(int h=0;h<n;h++){
if(h!=p&&(!(j&(1<<h)))&&y[i]+d>=y[h]){
memo[i][j]+=dp(h,j^(1<<h));
memo[i][j]%=MOD;
}
}
return memo[i][j];
}
void solve(){
memset(memo,-1,sizeof(memo));
cin>>n>>d;
for(int i=0;i<n;i++){
cin>>y[i];
}
y[n]=1e9;
long long ans=0;
for(int i=0;i<n;i++){
p=i;
memset(memo,-1,sizeof(memo));
ans+=dp(i,0);
ans%=MOD;
}
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
// Bac Math 2k24
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
172676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
172664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
172652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
308 ms |
172728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
501 ms |
172604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1081 ms |
172664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
172564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
470 ms |
172676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
930 ms |
172620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
260 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
250 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
255 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
260 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
253 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
252 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
265 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
264 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
271 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
270 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
290 ms |
262144 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |