Submission #825113

#TimeUsernameProblemLanguageResultExecution timeMemory
825113tch1cherinThe short shank; Redemption (BOI21_prison)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N, D, T; cin >> N >> D >> T; vector<int> pi(N, N); stack<pair<int, int>> S; int max_r = -1; int active = 0, passive = 0; for (int i = 0; i < N; i++) { int t; cin >> t; active += t <= T; max_r = max(max_r, i + T - t); if (!S.empty()) { S.top().second = max(S.top().second, i + T - t); } if (t > T && i <= max_r) { passive++; pi[i] = N; while (!S.empty() && S.top().second < i) { pi[S.top().first] = i; S.pop(); } S.emplace(i, -1); } else { pi[i] = -1; } } vector<int> depth(N + 1, -1); depth[N] = 0; for (int i = N - 1; i >= 0; i--) { if (pi[i] != -1) { depth[i] = depth[pi[i]] + 1; } } vector<int> ord(N); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int i, int j) { return depth[i] > depth[j]; }); vector<int> c(N); vector<bool> used(N); for (int i : ord) { if (pi[i] == -1) { continue; } int j = i; while (j < N && !used[j]) { c[i]++; used[j] = true; j = pi[j]; } } sort(c.rbegin(), c.rend()); cout << active + passive - accumulate(c.begin(), c.end(), 0) << "\n"; }
#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...