이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |