Submission #697302

#TimeUsernameProblemLanguageResultExecution timeMemory
697302Dan4LifeThe short shank; Redemption (BOI21_prison)C++17
35 / 100
205 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define int long long #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mxN = (int)1e5+10; const int LINF = (int)1e18; int n, k, T, a[mxN]; vector<vector<int>> dp,calc; void dnc(int l, int r, int optl, int optr, int i) { if (l > r) return; int mid = (l+r)/2; pair<int,int> best = {LINF, 1}; for (int k = optl; k <= min(mid, optr); k++) best = min(best, {dp[k-1][i]+calc[k][mid],k}); dp[mid][i+1] = best.fi; dnc(l,mid-1,optl,best.se,i); dnc(mid+1,r,best.se,optr,i); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k >> T; k++; calc.resize(n+2,vector<int>(n+2,0)); dp.resize(n+2,vector<int>(k+2,LINF)); for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++){ int ans = 0, mn = a[i]; for(int j = i; j <= n; j++) mn = min(mn+1, a[j]), ans+=(mn<=T), calc[i][j] = ans; } for(int i = 1; i <= n; i++) dp[i][1] = calc[1][i]; for(int i = 1; i < k; i++) dnc(1,n,1,n,i); cout << dp[n][k]; }
#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...