Submission #570513

#TimeUsernameProblemLanguageResultExecution timeMemory
570513cheissmartThe short shank; Redemption (BOI21_prison)C++14
100 / 100
681 ms320320 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(v) int((v).size()) #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m"; void DBG() { cerr << "]" << _reset << endl; } template<class H, class...T> void DBG(H h, T ...t) { cerr << to_string(h); if(sizeof ...(t)) cerr << ", "; DBG(t...); } #ifdef CHEISSMART #define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define debug(...) #endif const int INF = 1e9 + 7, N = 2e6 + 7; int a[N], p[N], down[N]; vi G[N]; void dfs(int u) { down[u] = 1; for(int v:G[u]) { dfs(v); down[u] = max(down[u], down[v] + 1); } } vi hebe[N]; signed main() { IO_OP; int n, d, t; cin >> n >> d >> t; int ans = n; V<pi> stk, aux; for(int i = 0; i < n; i++) { cin >> a[i]; if(a[i] <= t) { int r = i + t - a[i]; while(SZ(stk) && stk.back().S <= r) stk.pop_back(); stk.EB(i, r); } else { while(SZ(stk) && stk.back().S < i) stk.pop_back(); if(SZ(stk)) { // [stk.back().F, i) aux.EB(i, (i + 1)); aux.EB(stk.back().F, -(i + 1)); } else { ans--; } } } sort(ALL(aux), greater<>()); vi nodes; int lst = 0, tp = 1; for(auto[pos, op]:aux) { int u = abs(op); if(op > 0) { if(tp == 1) p[u] = lst; else p[u] = p[lst]; nodes.PB(u); } lst = u, tp = op > 0; } for(int u:nodes) if(p[u]) { G[p[u]].PB(u); } for(int u:nodes) if(!p[u]) { dfs(u); hebe[down[u]].PB(u); } function<void(int)> go = [&] (int u) { int nxt = -1; for(int v:G[u]) if(down[v] + 1 == down[u]) nxt = v; for(int v:G[u]) if(v != nxt) hebe[down[v]].PB(v); if(nxt != -1) go(nxt); }; for(int i = n; i >= 1 && d; i--) { while(d && SZ(hebe[i])) { int u = hebe[i].back(); hebe[i].pop_back(); go(u); assert(down[u] == i); ans -= i; d--; } } cout << ans << '\n'; }

Compilation message (stderr)

prison.cpp: In function 'int main()':
prison.cpp:78:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |  for(auto[pos, op]:aux) {
      |          ^
#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...