제출 #1021724

#제출 시각아이디문제언어결과실행 시간메모리
102172412345678The short shank; Redemption (BOI21_prison)C++17
35 / 100
778 ms136600 KiB
#include <bits/stdc++.h> using namespace std; const int nx=4e3+5; int n, d, T, dp[nx][nx], c[nx][nx], t[nx], lst; void solve(int l, int r, int layer, int optl, int optr) { if (r<l) return; int md=(l+r)/2; //cout<<"debug "<<md<<' '<<optl<<' '<<optr<<'\n'; pair<int, int> mn={INT_MAX, 0}; for (int i=optl; i<=min(optr, md); i++) mn=min(mn, {dp[layer-1][i-1]+c[i][md], i}); //cout<<"md "<<md<<' '<<mn.first<<' '<<mn.second<<'\n'; dp[layer][md]=mn.first; solve(l, md-1, layer, optl, mn.second); solve(md+1, r, layer, mn.second, optr); } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>d>>T; for (int i=1; i<=n; i++) cin>>t[i]; for (int i=0; i<=n; i++) for (int j=0; j<=n; j++) dp[i][j]=1e9; dp[0][0]=0; for (int i=1; i<=n; i++) { int cnt=0, lst=1e9; for (int j=i; j<=n; j++) lst=min(lst+1, t[j]), cnt+=(lst<=T), c[i][j]=cnt; } for (int i=1; i<=d+1; i++) solve(i, n, i, i, n); //for (int i=1; i<=d+1; i++) for (int j=1; j<=n; j++) cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n'; cout<<dp[d+1][n]; }
#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...