Submission #508768

#TimeUsernameProblemLanguageResultExecution timeMemory
508768ElegiaThe short shank; Redemption (BOI21_prison)C++17
0 / 100
63 ms8024 KiB
#include <cmath> #include <algorithm> #include <stack> #include <bitset> #include <numeric> #include <iostream> #include <vector> #include <string> #include <set> #include <queue> #include <map> #include <unordered_map> using ull = unsigned long long; using namespace std; // const int P = 998244353; // int norm(int x) { return x >= P ? x - P : x; } // int reduce(int x) { return x < 0 ? x + P : x; } // int neg(int x) { return x ? P - x : 0; } // void add(int& x, int y) { if ((x += y - P) < 0) x += P; } // void sub(int& x, int y) { if ((x -= y) < 0) x += P; } // void fam(int& x, int y, int z) { x = (x + y * (ull)z) % P; } // int mpow(int x, unsigned k) { // if (k == 0) return 1; // int ret = mpow(x * (ull)x % P, k >> 1); // if (k & 1) ret = ret * (ull)x % P; // return ret; // } // int quo2(int x) { return ((x & 1) ? x + P : x) >> 1; } const int _ = 2000010; int ans; int t[_], l[_], r[_], cnt[_], mx[_]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int N, D, T; cin >> N >> D >> T; for (int i = 1; i <= N; ++i) cin >> t[i]; stack<int> stk; for (int i = N; i; --i) { if (t[i] > T) continue; ++ans; int lst = l[ans] = i; r[ans] = min(N, i + T - t[i]); while (true) { if (!stk.empty() && r[ans] > r[stk.top()]) { int p = stk.top(); stk.pop(); --cnt[mx[ans]]; ++cnt[mx[ans] += l[p] - lst - 1]; mx[ans] = max(mx[ans], mx[p]); lst = r[p]; } else { if (!stk.empty()) r[ans] = l[stk.top()] - 1; --cnt[mx[ans]]; ++cnt[mx[ans] += r[ans] - lst]; break; } } stk.push(ans); } for (int i = N; i; --i) { int v = min(D, cnt[i]); D -= v; cnt[i] -= v; } for (int i = 1; i <= N; ++i) ans += cnt[i] * i; 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...