Submission #1032548

#TimeUsernameProblemLanguageResultExecution timeMemory
1032548HorizonWestThe short shank; Redemption (BOI21_prison)C++17
55 / 100
342 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #define endl '\n' #define db double #define ll __int128 #define int long long #define pb push_back #define fs first #define sd second #define Mod long(1e9 + 7) #define all(x) x.begin(), x.end() #define unvisited long(-1) #define Eps double(1e-9) #define _for(i, n) for(int i = 0; i < (n); i++) #define dbg(x) cout << #x ": " << x << endl; const int Max = 1e6 + 7, Inf = 1e9 + 7; void print(bool x) { cout << (x ? "YES" : "NO") << endl; } string tostring (__int128 x) { string ans = ""; while(x > 0) { ans += (x % 10 + '0'); x /= 10; } reverse(all(ans)); return ans; } struct SegmentTreeLazy { struct node { int value, lazy; node(int v = 0) { value = v; lazy = 0; } }; vector <node> tree; int l; void update(int v, int s, int e, int k) { tree[v].lazy += k; tree[v].value += k; } void push(int v, int s, int e) { if (tree[v].lazy) { int middle = (s + e) / 2; update(2 * v, s, middle, tree[v].lazy); update(2 * v + 1, middle + 1, e, tree[v].lazy); tree[v].lazy = 0; } } void increase(int node, int v, int x, int y, int s, int e) { if (s > y || e < x) return; if (s >= x && e <= y) { update(node, s, e, v); return; } push(node, s, e); int middle = (s + e) / 2; increase(node * 2, v, x, y, s, middle); increase(node * 2 + 1, v, x, y, middle + 1, e); tree[node].value = max(tree[node * 2].value, tree[node * 2 + 1].value); } void increase(int x, int y, int k) { increase(1, k, x+1, y+1, 1, l); } int sum(int node, int x, int y, int s, int e) { if (s > y || e < x) return 0; if (s >= x && e <= y) return tree[node].value; push(node, s, e); int middle = (s + e) / 2; return max(sum(node * 2, x, y, s, middle), sum(node * 2 + 1, x, y, middle + 1, e)); } int query(int x, int y) { return sum(1, x+1, y+1, 1, l); } SegmentTreeLazy(int n) { for (l = 1; l < n; l = (l << 1)); tree.resize(2 * l); } }; void solve() { int n, d, t; cin >> n >> d >> t; vector <int> v(n), c(n, -1); for(auto& u : v) cin >> u; stack <int> q; for(int i = n-1; i >= 0; i--) { if(v[i] > t){ q.push(i); continue; } while (!q.empty()) { int x = q.top(); if(abs(t-v[i]) >= abs(x-i)){ c[x] = i; q.pop(); } else break; } } vector <SegmentTreeLazy> dp(d+1, SegmentTreeLazy(n+1)); auto f = [&](int i, int j) { if(c[i] == -1) return 0LL; return ((int) (c[i] <= j && j < i)); }; int ans = 0; for(int i = 0; i < n; i++) { for(int k = 1; k <= d; k++){ if(c[i] != -1) { dp[k].increase(c[i], i-1, 1); } dp[k].increase(i, i, dp[k-1].query(0, i)); } } ans = dp[d].query(0, n-1); cout << (n - (ans + q.size())) << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int Q = 1; //cin >> Q; while (Q--) { solve(); } return 0; }

Compilation message (stderr)

prison.cpp: In function 'void solve()':
prison.cpp:141:10: warning: variable 'f' set but not used [-Wunused-but-set-variable]
  141 |     auto f = [&](int i, int j) {
      |          ^
#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...