제출 #1056726

#제출 시각아이디문제언어결과실행 시간메모리
1056726AmirAli_H1송신탑 (IOI22_towers)C++17
23 / 100
4073 ms5076 KiB
// In the name of Allah #include <bits/stdc++.h> #include "towers.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define F first #define S second #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define Mp make_pair #define pb push_back #define endl '\n' #define sep ' ' const int maxn = 1e5 + 7; const ll oo = 1e9 + 7; int n; ll Ax[maxn], A[maxn]; set<int> st; int arr[maxn]; bool cmp(int i, int j) { return (A[i] < A[j]); } void init(int N, vector<int> H) { n = N; for (int i = 0; i < n; i++) Ax[i] = H[i]; } bool check(int i, int j, int D) { if (j - i + 1 <= 2) return 0; int mx = *max_element(A + i + 1, A + j); return (mx >= max(A[i], A[j]) + D); } bool ok(int i, int D) { auto it = st.lower_bound(i); if (it != st.end()) { if (!check(i, *it, D)) return 0; } if (it != st.begin()) { it--; if (!check(*it, i, D)) return 0; } return 1; } int max_towers(int L, int R, int D) { for (int j = L; j <= R; j++) A[j - L] = Ax[j]; n = R - L + 1; st.clear(); iota(arr, arr + n, 0); sort(arr, arr + n, cmp); for (int j = 0; j < n; j++) { int i = arr[j]; if (ok(i, D)) st.insert(i); } return len(st); }
#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...