Submission #866945

#TimeUsernameProblemLanguageResultExecution timeMemory
866945HossamHero7The short shank; Redemption (BOI21_prison)C++14
35 / 100
2082 ms129112 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int dp[4005][2]; int cost[4005][4005]; void calc(int l,int r,int opt1,int opt2,int k){ if(l > r) return; int i = l + r >> 1; pair<int,int> opt{1e9,-1}; for(int p=opt1;p<=min(opt2,r);p++){ if(p) opt = min(opt,{dp[p-1][k-1&1]+cost[p][i],p}); else opt = min(opt,{cost[0][i],p}); } dp[i][k&1] = opt.first; calc(l,i-1,opt1,opt.second,k); calc(i+1,r,opt.second,opt2,k); } void solve(){ int n,d,t; cin>>n>>d>>t; vector<int> v(n); for(auto &i:v) cin>>i; for(int i=0;i<n;i++){ int lst = v[i]; cost[i][i] = (lst <= t); for(int j=i+1;j<n;j++) { cost[i][j] += cost[i][j-1]; if(v[j] > lst) lst ++; else lst = v[j]; cost[i][j] += (lst <= t); } } for(int i=0;i<n;i++) dp[i][0] = cost[0][i]; for(int k=1;k<=d;k++){ calc(0,n-1,0,n-1,k); } cout<<dp[n-1][d&1]<<endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

prison.cpp: In function 'void calc(int, int, int, int, int)':
prison.cpp:9:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    9 |     int i = l + r >> 1;
      |             ~~^~~
prison.cpp:12:39: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   12 |         if(p) opt = min(opt,{dp[p-1][k-1&1]+cost[p][i],p});
      |                                      ~^~
#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...