Submission #868312

#TimeUsernameProblemLanguageResultExecution timeMemory
868312overwatch9A Huge Tower (CEOI10_tower)C++17
15 / 100
202 ms19628 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; const int mod = 1e9 + 9; vector <ll> dp, nums, perm; int n, d; ll solve(int i) { if (i <= 0) return 1; if (dp[i] != -1) return dp[i]; int l = lower_bound(nums.begin() + 1, nums.end(), nums[i] - d) - nums.begin(); int r = upper_bound(nums.begin() + 1, nums.end(), nums[i] + d) - nums.begin(); r--; ll ans = solve(l-1) * perm[r - l + 1]; ans %= mod; dp[i] = ans; return ans; } int main() { cin >> n >> d; dp.resize(n+1, -1); nums.resize(n+1); perm.resize(n+1); perm[1] = 1; for (int i = 2; i <= n; i++) perm[i] = (perm[i-1] * i) % mod; for (int i = 1; i <= n; i++) cin >> nums[i]; sort(nums.begin(), nums.end()); cout << solve(n) << '\n'; }
#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...