Submission #531261

#TimeUsernameProblemLanguageResultExecution timeMemory
531261hohohahaA Huge Tower (CEOI10_tower)C++14
45 / 100
330 ms82372 KiB
#include<bits/stdc++.h> using namespace std; #define fori(i, a, b) for(int i = (int) (a); i <= (int) (b); i++) #define ford(i, a, b) for(int i = (int) (a); i >= (int) (b); i--) #define ii pair<int, int> #define fi first #define se second #define vi vector<int> #define eb emplace_back #define sp ' ' #define int long long const int maxn = 3e6 + 5, mod = 1e9 + 9; int n, d; int arr[maxn]; int dp[1 << 20][20]; signed main() { // freopen("tower.inp", "r", stdin); // freopen("tower.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> d; fori(i, 0, n - 1) cin >> arr[i]; fori(i, 0, n - 1) dp[1 << i][i] = 1; fori(mask, 1, (1 << n) - 1) { fori(last, 0, n - 1) { if(mask >> last & 1) { fori(nxt, 0, n - 1) { if(!(mask >> nxt & 1)) { if(arr[nxt] <= arr[last] + d) { dp[mask ^ (1 << nxt)][nxt] += dp[mask][last]; if(dp[mask ^ (1 << nxt)][nxt] >= mod) dp[mask ^ (1 << nxt)][nxt] -= mod; } } } } } } int ans = 0; fori(last, 0, n - 1) (ans += dp[(1 << n) - 1][last]) %= mod; cout << ans; }
#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...