#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define file freopen("in.txt", "r", stdin);
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(), v.end()
#define keepunique(v) (v).erase(unique(all(v)),v.end())
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);
const int maxn = 5005;
#define int ll
int arr[maxn], n, k, mark[maxn], cnt = 0;
vector<int> vec;
int dp[maxn];
int call(int u){
int ans = 0;
if(dp[u] != -1)return dp[u];
for(int i=u+1; i<n; i++){
if(mark[arr[i]] >= mark[arr[u]]){
if(call(i) >= ans)ans = call(i);
}
}
return dp[u] = 1+ans;
}
int solve(){
int lon = 0;
for(int i=0; i<n; i++){
memset(dp, -1, sizeof dp);
lon = max(lon, call(i));
}
return n - lon;
}
int32_t main(){
//file
fastread
cin>>n>>k;
for(int i=0; i<n; i++){
cin>>arr[i];
vec.pb(arr[i]);
}
//vec1 = vec;
sort(all(vec));
for(int i=0; i<n; i++){
if(i%k == 0)++cnt;
mark[vec[i]] = cnt;
}
cout<<solve()<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
644 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
784 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1056 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1232 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1244 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |