Submission #1057637

#TimeUsernameProblemLanguageResultExecution timeMemory
1057637mtshastaA Huge Tower (CEOI10_tower)C++17
100 / 100
83 ms13140 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9 + 9; void solve() { int n, d; cin >> n >> d; vector<int> b(n); vector<ll> ans(n); for (int i = 0; i < n; ++i) { cin >> b[i]; } sort(b.begin(), b.end()); ans[0] = 1; int cnt = 1; for (int i = 1; i < n; ++i) { auto ok = [&](int x) -> bool { return b[i] <= b[x] + d; }; int l = i - cnt, r = i, res; while (l <= r) { int mid = l + (r - l) / 2; if (!ok(mid)) l = mid + 1; else { res = mid; r = mid - 1; } } ans[i] = ans[i - 1] * (i - res + 1); ans[i] %= MOD; cnt = i - res + 1; } cout << ans[n - 1] << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

Compilation message (stderr)

tower.cpp: In function 'void solve()':
tower.cpp:31:34: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |         ans[i] = ans[i - 1] * (i - res + 1);
      |                                ~~^~~~~
#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...