제출 #729097

#제출 시각아이디문제언어결과실행 시간메모리
729097_martynasThe short shank; Redemption (BOI21_prison)C++11
100 / 100
981 ms75612 KiB
#include <bits/stdc++.h> using namespace std; #define PB push_back #define all(a) (a).begin(), (a).end() const int MXN = 2e6+5; int n, d, t; int T[MXN]; int always = 0, perchance = 0, preventable = 0; bool maybe[MXN]; int covered_by[MXN], par[MXN], H[MXN], who[MXN]; bool visited[MXN]; int main() { cin >> n >> d >> t; for(int i = 1; i <= n; i++) cin >> T[i]; stack<int> st; for(int i = n; i >= 1; i--) { while(!st.empty() && st.top()-i <= t-T[i]) { covered_by[st.top()] = i; maybe[st.top()] = true; perchance++; st.pop(); } if(T[i] > t) st.push(i); else always++; } stack<int> open, closing; for(int i = n; i >= 1; i--) { while(!closing.empty() && closing.top() == i) open.pop(), closing.pop(); if(!maybe[i]) continue; if(!open.empty()) { par[i] = open.top(); } open.push(i); closing.push(covered_by[i]); } vector<int> order; for(int i = 1; i <= n; i++) { if(!maybe[i]) continue; if(par[i] != 0) { if(H[par[i]] < H[i]+1) { H[par[i]] = H[i]+1; who[par[i]] = i; } } order.PB(i); } sort(all(order), [&](int i, int j) { return H[i] > H[j]; }); for(int i : order) { if(visited[i]) continue; if(!d) break; int j = i; while(j) { preventable++; visited[j] = true; j = who[j]; } d--; } cout << always+(perchance-preventable) << "\n"; return 0; } /* 1 1 1 2 */
#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...