제출 #666419

#제출 시각아이디문제언어결과실행 시간메모리
666419MilosMilutinovicThe short shank; Redemption (BOI21_prison)C++14
35 / 100
2083 ms4320 KiB
/** * author: wxhtzdy * created: 28.11.2022 15:11:47 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, d, t; cin >> n >> d >> t; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> prv(n); vector<int> stk; for (int i = 0; i < n; i++) { prv[i] = -1; for (int j = 0; j <= i; j++) { if (a[j] + (i - j) <= t) { prv[i] = j; } } /* while (!stk.empty() && a[stk.back()] + i - stk.back() > t) { stk.pop_back(); } while (!stk.empty() && a[stk.back()] - stk.back() > a[i] - i) { stk.pop_back(); } prv[i] = (a[i] <= t ? i : (stk.empty() ? -1 : stk.back())); stk.push_back(i); */ } int ans = 0; vector<int> cnt(n); for (int i = 0; i < n; i++) { if (prv[i] != -1) { ans += 1; for (int j = prv[i]; j < i; j++) { cnt[j] += 1; } } } set<pair<int, int>> st; for (int i = 0; i + 1 < n; i++) { st.emplace(cnt[i], i); } vector<bool> rem(n); for (int i = 0; i < d; i++) { auto it = prev(st.end()); int idx = it->second; ans -= it->first; st.erase(it); rem[idx] = true; for (int j = idx + 1; j < n; j++) { if (prv[j] != -1 && prv[j] <= idx) { for (int k = prv[j]; k < j; k++) { if (!rem[k]) { st.erase(make_pair(cnt[k], k)); cnt[k] -= 1; st.emplace(cnt[k], k); } prv[j] = -1; } } } } cout << ans << '\n'; return 0; }
#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...