Submission #866462

#TimeUsernameProblemLanguageResultExecution timeMemory
866462MisterReaperA Huge Tower (CEOI10_tower)C++17
20 / 100
965 ms173000 KiB
//author: Ahmet Alp Orakci #include <bits/stdc++.h> using namespace std; using i64 = long long; const int MOD = 1E9 + 7; int dp[20][1 << 20]; int arr[20]; #define ONLINE_JUDGE void solve() { memset(dp, -1, sizeof(dp)); int n, d; cin >> n >> d; for(int i = 0; i < n; i++) cin >> arr[i]; function <int(int, int)> f = [&](int last, int mask) -> int { if(mask == (1 << n) -1) return 1; if(dp[last][mask] != -1) return dp[last][mask]; int res = 0; for(int i = 0; i < n; i++) { if(!(mask & (1 << i)) && arr[i] <= d + arr[last]) { (res += f(i, mask | (1 << i))) %= MOD; } } return dp[last][mask] = res; }; int res = 0; for(int i = 0; i < n; i++) { (res += f(i, (1 << i))) %= MOD; } cout << res; return; } signed main() { #ifndef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; for(int i = 1; i <= t; i++) { solve(); } 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...