Submission #393557

#TimeUsernameProblemLanguageResultExecution timeMemory
393557aaronhmaA Huge Tower (CEOI10_tower)C++17
100 / 100
129 ms5068 KiB
// O(n log n + n) #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) begin(x), end(x) #define FORE(i, a, b) for (ll i = a; i < b; i++) const int MOD = 1e9 + 9; // 10^9 + 9 for "CEOI 2010 - A Huge Tower" // INPUT template <class T> void read(T &x) { cin >> x; } template <class T> void read(vector<T> &a) { FORE(i, 0, (int)a.size()) read(a[i]); } template <class Arg, class... Args> void read(Arg &first, Args &...rest) { read(first); read(rest...); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // ans: We'll set the answer to 1. // j: Current index that we can build start from arr[0] (j = 0 is a dummy value) ll n, d, ans = 1, j = 0; read(n, d); vll arr(n); read(arr); // Sort the blocks in increasing order sort(all(arr)); // Let i = starting index of the first block possible. FORE(i, 0, n) { // Find the maximum index possible that we can build starting from arr[i] as the base while (j < n && arr[j] - arr[i] <= d) j++; // j - i: Largest tower we can build when arr[i] is the base ans *= j - i; // Make the answer within range ans %= MOD; } cout << ans << "\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...