Submission #1116619

#TimeUsernameProblemLanguageResultExecution timeMemory
111661912345678Studentsko (COCI14_studentsko)C++17
10 / 100
6 ms788 KiB
#include <bits/stdc++.h> using namespace std; const int nx=5e3+5; int n, k, v[nx], t, l[nx], r[nx], g, res=INT_MAX, dp[nx]; map<int, int> mp; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>k; g=n/k; for (int i=1; i<=n; i++) cin>>v[i], mp[-v[i]]=0, l[i]=INT_MAX, r[i]=0; for (auto &[x, y]:mp) y=(t/k)+1, t++; for (int i=1; i<=n; i++) v[i]=mp[-v[i]], l[v[i]]=min(l[v[i]], i), r[v[i]]=max(r[v[i]], i); for (int i=1; i<=g; i++) { dp[i]=i; if (i>1&&r[i]<l[i-1]) dp[i]=dp[i-1]; //cout<<"dp "<<i<<' '<<dp[i]<<'\n'; int cur=(n-(i-dp[i]+1)*k); for (int j=r[dp[i]]+1; j<=n; j++) if (v[j]==dp[i]-1) cur--; for (int j=1; j<l[i]; j++) if (v[j]==i+1) cur--; res=min(res, cur); } cout<<res; }
#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...