Submission #866942

#TimeUsernameProblemLanguageResultExecution timeMemory
866942HossamHero7The short shank; Redemption (BOI21_prison)C++14
15 / 100
280 ms524288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int dp[505][2]; void solve(){ int n,d,t; cin>>n>>d>>t; vector<int> v(n); for(auto &i:v) cin>>i; vector<vector<int>> cost(n,vector<int>(n)); 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++){ for(int i=0;i<n;i++){ pair<int,int> opt{1e9,-1}; for(int p=0;p<=i;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; } } 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 solve()':
prison.cpp:27:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   27 |                 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...