Submission #1074034

#TimeUsernameProblemLanguageResultExecution timeMemory
1074034Gromp15Radio Towers (IOI22_towers)C++17
11 / 100
4075 ms180176 KiB
#include <bits/stdc++.h> #include "towers.h" #define ll long long #define ar array #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() using namespace std; template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; } int N; vector<int> h; void init(int _N, std::vector<int> H) { N = _N; h = H; } struct seg { int N; vector<ar<int, 2>> tree; seg(int n, const vector<int>& h) : N(1<<(__lg(n)+1)), tree(2*N) { for (int i = 0; i < n; i++) tree[i+N] = {h[i], i}; for (int i = N-1; i >= 1; i--) tree[i] = max(tree[i*2], tree[i*2+1]); } ar<int, 2> query(int node, int nl, int nr, int ql, int qr) { if (ql > nr || qr < nl) return {}; if (ql <= nl && nr <= qr) return tree[node]; int mid = (nl+nr)/2; return max(query(node*2, nl, mid, ql, qr), query(node*2+1, mid+1, nr, ql, qr)); } }; int max_towers(int L, int R, int D) { seg st(N, h); map<ar<int, 3>, int> mp; auto solve = [&](auto&& s, int l, int r, int lim) -> int { if (mp.count({l, r, lim})) return mp[{l, r, lim}]; if (l > r) return 0; if (l == r) return h[l] <= lim; int p = st.query(1, 0, st.N-1, l, r)[1]; return mp[{l, r, lim}] = max({s(s, l, p-1, lim), s(s, p+1, r, lim), int(h[p] <= lim), s(s, l, p-1, h[p] - D) + s(s, p+1, r, h[p] - D)}); }; solve(solve, L, R, 1e9); return solve(solve, L, R, 1e9); }
#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...