# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
866942 | HossamHero7 | The short shank; Redemption (BOI21_prison) | C++14 | 280 ms | 524288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |