Submission #755933

#TimeUsernameProblemLanguageResultExecution timeMemory
755933vjudge1A Huge Tower (CEOI10_tower)C++17
45 / 100
1082 ms208416 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...