Submission #886517

#TimeUsernameProblemLanguageResultExecution timeMemory
886517stefanneaguA Huge Tower (CEOI10_tower)C++17
30 / 100
210 ms4516 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e6 + 1, mod = 1e9 + 9; int v[nmax], n, h; long long ans; bool f[nmax]; void dfs(int x, int cnt) { if(cnt == n) { ans ++; } for(int i = 1; i <= n; i ++) { if(!f[i] && v[x] + h >= v[i]) { f[i] = 1; dfs(i, cnt + 1); f[i] = 0; } } } int main() { cin >> n >> h; for(int i = 1; i <= n; i ++) { cin >> v[i]; } sort(v + 1, v + n + 1, greater<int>()); if(n > 14) { int curr = 1; ans = 1; for(int i = 1; i <= n; i ++) { if(v[curr] > v[i] + h) { curr ++; } ans = ans * (i - curr + 1); ans %= mod; } cout << ans; return 0; } for(int i = 1; i <= n; i ++) { f[i] = 1; dfs(i, 1); f[i] = 0; } cout << ans; 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...