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;
#define endl '\n'
#define ins insert
#define pb push_back
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<
const int mod = 1e9+7 ,
sze= 5000 + 23 ,
inf = INT_MAX ,
L = 31 ;
int dp[sze][sze];
void opt1z(){
int n,k;
cin>>n>>k;
vector<int> arr(n),color(n);
multiset<int> lst;
map<int,vector<int>> idx;
for(int i=0;i<n;i++){
cin>>arr[i];
idx[arr[i]].pb(i);
lst.ins(arr[i]);
}
for(auto &v:idx){
reverse(all(v.second));
}
int c = 1;
int nm = 0;
while(!lst.empty()){
nm++;
if(nm==k+1){
nm=1;
c++;
}
color[idx[*lst.begin()].back()]=c;
idx[*lst.begin()].pop_back();
lst.erase(lst.begin());
}
// for(auto v:color){
// cout<<v<<" ";
// }
// cout<<endl;
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
dp[i][color[i]] = max({dp[i][color[i]],dp[j][color[i] -1]+1, dp[j][color[i]] +1 });
// cout<<i _ j _ color[i] _ dp[i][color[i]]<<endl;
}
dp[i][color[i]]=max(dp[i][color[i]],1);
ans=max(ans,dp[i][color[i]]);
}
putr(n - ans);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
// cin>>tt;
while(tt--){
opt1z();
}
return 0;
}
# | 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... |
# | 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... |