Submission #1095594

#TimeUsernameProblemLanguageResultExecution timeMemory
10955940pt1mus23Studentsko (COCI14_studentsko)C++14
100 / 100
25 ms1292 KiB
#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]; 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++){ dp[i]=1; for(int j=0;j<i;j++){ if(color[j]<=color[i]){ dp[i]=max(dp[i],dp[j]+1); } } ans=max(ans,dp[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 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...