제출 #1218563

#제출 시각아이디문제언어결과실행 시간메모리
1218563banganRadio Towers (IOI22_towers)C++20
0 / 100
4094 ms1948 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; #define chmax(a, b) a = max(a, b) #define pb push_back const int maxn = 1e5 + 4; int n; int h[maxn]; int dp[maxn]; int pre[maxn]; int local_min(int i) { if (1 <= i-1 && h[i] > h[i-1]) return 0; if (i+1 <= n && h[i] > h[i+1]) return 0; return 1; } void init(int N, std::vector<int> H) { n = N; for (int i=1; i<=n; i++) h[i] = H[i-1]; for (int i=1; i<=n; i++) pre[i] = pre[i-1] + local_min(i); } int max_towers(int L, int R, int D) { if (L==R) return 1; L++; R++; vector<int> stk{1}; { int mx = 0; for (int i = 2; i <= n; i++) { if (h[i] <= mx-D && h[stk.back()] <= mx-D) stk.pb(i), mx=0; else if (h[i] < h[stk.back()]) { stk.pop_back(); stk.pb(i); mx=0; } else chmax(mx, h[i]); } } int ans = 0; for (int i : stk) if (L<=i && i<=R) ans++; if (ans == 0) { for (int i=L; i<=R; i++) { for (int j=i+1, mx=0; j<=R; j++) { if (h[i] <= mx+D && h[j] <= mx+D) return 2; chmax(mx, h[j]); } } return 1; } int f = *lower_bound(stk.begin(), stk.end(), L); for (int i = f-1, mx=0; i >= L; i--) { if (h[i] <= mx-D && h[f] <= mx-D) return ans+1; chmax(mx, h[i]); } return ans; }
#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...