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 <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif
const int md = 1000000009;
const int MaxN = 1 << 20;
int add(int &a, int b) {
a += b;
if (a > md) {
a -= md;
}
return a;
}
int dp[MaxN + 1][25];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d;
cin >> n >> d;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = -1;
}
}
function<int(int, int)> DP = [&](int mask, int prev) {
if (mask == (1 << n) - 1) {
return 1;
}
if (dp[mask][prev + 1] != -1) {
return dp[mask][prev + 1];
}
int ways = 0;
for (int j = 0; j < n; j++) {
if ((1 << j) & mask || (prev > -1 && a[j] - d > a[prev])) {
continue;
}
add(ways, DP(mask | (1 << j), j));
}
return dp[mask][prev + 1] = ways;
};
cout << DP(0, -1) << '\n';
return 0;
}
# | 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... |