제출 #1123092

#제출 시각아이디문제언어결과실행 시간메모리
1123092crafticatThe short shank; Redemption (BOI21_prison)C++20
55 / 100
1370 ms589824 KiB
#include <bits/stdc++.h> using namespace std; #define F0R(i, n) for (int i = 0; i < n;i++) #define FOR(i, j, n) for (int i = j;i < n;i++) template<typename T> using V = vector<T>; using vi = V<int>; constexpr int INF = 1e9 + 7; using pi = pair<int,int>; int T; struct Seg { Seg *left = nullptr, *right = nullptr; int l, r, mid; int v = -INF, lazy = 0; void push() { if (lazy == 0) return; if (r -l >1) { left->lazy += lazy; right->lazy += lazy; } v += lazy; lazy = 0; } Seg(int l ,int r) : l(l), r(r), mid((l + r) / 2) { if (r -l > 1) { left = new Seg(l, mid); right = new Seg(mid, r); } } void add(int a, int b, int u) { push(); if (b <= l || a >= r) return; if (a <= l && b >= r) { lazy += u; push(); return; } left->add(a, b, u); right->add(a,b,u); v = max(left->v, right->v); } void update(int x, int u) { push(); if (r - l <= 1) { v = max(v, u); return; } if (x < mid) left->update(x,u); else right->update(x,u); v = max(left->v, right->v); } }; V<vi> createSeg; // imd V<vi> remSeg; // At end int solve(vi arr, int k) { multiset<int> v; V<Seg*> segs(k + 1); F0R(i, k + 1) segs[i] = new Seg(0, arr.size() + 1); segs[0]->update(0, 0); FOR(i, 1, arr.size() + 1) { for (auto v2 : createSeg[i - 1]) v.insert(v2); int rightMost = v.empty() ? -1 : *v.rbegin(); // Right most is alright (not inc) FOR(j, 1, k + 1) { int vR = segs[j - 1]->v; if (vR != 0) { int stop = 25; } segs[j]->update(i - 1,vR); } FOR(j, 0, k + 1) { segs[j]->add(rightMost + 1, i, 1); } for (auto v2 : remSeg[i - 1]) { v.erase(v.find(v2)); } } return segs[k]->v; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k >> T; vi arr(n); createSeg.resize(n + 1); remSeg.resize(n + 1); F0R(i, n) cin >> arr[i]; F0R(i, n) { int next = T - arr[i]; if (next < 0) continue; createSeg[i].push_back(i); remSeg[min(i + next, n)].push_back(i); } cout << n - solve(arr, k); 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...