#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <climits>
using namespace std;
#define input "tower.in"
#define output "tower.out"
#define int long long
#define MOD (int)(1e9+9)
int n, k;
vector<int> a_orig;
vector<int> a;
int ans=1;
bool within(int n1, int n2) {
return (n1+k>=n2);
}
int recurs(vector<bool> vis, int last) {
if (find(vis.begin(), vis.end(), 0) == vis.end()) return 1;
//for (int x: a) cout << x << ' ';
//cout << endl;
//for (bool b: vis) cout << b << ' ';
//cout << endl;
int curr_sum=0;
for (int i=0;i<a.size();i++) {
if (!within(last, a[i])) {
//cout << last << " not within " << a[i] << endl;
return curr_sum;
}
if (!vis[i]) {
vis[i] = true;
curr_sum += recurs(vis, a[i]);
vis[i] = false;
}
}
return curr_sum;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
//freopen(input, "r", stdin);
//freopen(output, "w", stdout);
cin >> n >> k;
a_orig.reserve(n);
a.reserve(n);
int x;
for (int i=0;i<n;i++) {
cin >> x;
a_orig.push_back(x);
}
sort(a_orig.begin(), a_orig.end());
a.push_back(a_orig[0]);
for (int i=1;i<n;i++) {
if (!within(a_orig[i-1], a_orig[i])) {
ans *= recurs(vector<bool>(a.size(), 0), INT_MAX);
a.clear();
}
a.push_back(a_orig[i]);
}
ans *= recurs(vector<bool>(a.size(), 0), INT_MAX);
cout << ans % MOD;
}
Compilation message
tower.cpp: In function 'long long int recurs(std::vector<bool>, long long int)':
tower.cpp:32:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i=0;i<a.size();i++) {
| ~^~~~~~~~~
# |
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 |
470 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1045 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
364 KB |
Time limit exceeded |
# |
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 |
Execution timed out |
1096 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1041 ms |
748 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1087 ms |
1260 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
14956 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1054 ms |
159044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
309 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
304 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |