10036 | 2024-03-25 16:32:01 | 111 | Növekvő Ödön és a Másoló Varázsló | cpp17 | Runtime error 25/100 | 4ms | 5524 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
if(N*M>100000){
return 1;
}
vector<int>v(N+1),w(M);
for(int i=1;i<=N;i++){
cin>>v[i];
}
for(int i=0;i<M;i++){
cin>>w[i];
}
sort(w.begin(),w.end());
vector<vector<int>>dp(N+1,vector<int>(M));
vector<int>ans(N+1);
for(int i=1;i<=N;i++){
for(int j=0;j<M;j++){
dp[i][j]=j==0?N*2:dp[i-1][j-1]+1;
if(w[j]>v[i-1]){
dp[i][j]=min(dp[i][j],ans[i-1]+!(v[i-1]<v[i]&&v[i]<w[j]));
}
}
int j=upper_bound(w.begin(),w.end(),v[i])-w.begin();
ans[i]=N*2;
if(j>0){
ans[i]=min(ans[i],dp[i][j-1]);
}
if(j>0){
ans[i]=min(ans[i],dp[i-1][j-1]);
}
if(v[i]>v[i-1]){
ans[i]=min(ans[i],ans[i-1]);
}
}
// for(int i=1;i<=N;i++){
// cout<<setw(4)<<ans[i]<<" | ";
// for(int j:dp[i]){
// cout<<setw(4)<<j<<' ';
// }
// cout<<'\n';
// }
cout<<min(ans[N],*min_element(dp[N].begin(),dp[N].end()))<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Runtime error | 3ms | 2028 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Runtime error | 3ms | 2256 KiB | ||||
4 | Runtime error | 3ms | 2480 KiB | ||||
5 | Runtime error | 2ms | 2556 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 2760 KiB | ||||
7 | Accepted | 3ms | 2880 KiB | ||||
8 | Accepted | 3ms | 3088 KiB | ||||
subtask4 | 15/15 | ||||||
9 | Accepted | 4ms | 4412 KiB | ||||
10 | Accepted | 4ms | 4628 KiB | ||||
11 | Accepted | 3ms | 4368 KiB | ||||
12 | Accepted | 4ms | 4996 KiB | ||||
subtask5 | 0/5 | ||||||
13 | Runtime error | 3ms | 3884 KiB | ||||
14 | Runtime error | 2ms | 3924 KiB | ||||
15 | Runtime error | 3ms | 3996 KiB | ||||
subtask6 | 0/5 | ||||||
16 | Runtime error | 3ms | 4000 KiB | ||||
17 | Runtime error | 3ms | 4128 KiB | ||||
18 | Runtime error | 3ms | 4224 KiB | ||||
19 | Runtime error | 3ms | 4216 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Runtime error | 3ms | 4312 KiB | ||||
21 | Runtime error | 3ms | 4212 KiB | ||||
22 | Runtime error | 3ms | 4588 KiB | ||||
23 | Runtime error | 2ms | 4480 KiB | ||||
24 | Runtime error | 3ms | 4548 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 3ms | 4660 KiB | ||||
26 | Runtime error | 2ms | 4656 KiB | ||||
27 | Runtime error | 2ms | 4552 KiB | ||||
28 | Accepted | 3ms | 4652 KiB | ||||
29 | Runtime error | 2ms | 4540 KiB | ||||
30 | Runtime error | 3ms | 4768 KiB | ||||
31 | Runtime error | 2ms | 4764 KiB | ||||
32 | Runtime error | 2ms | 4764 KiB | ||||
33 | Runtime error | 2ms | 4768 KiB | ||||
34 | Runtime error | 3ms | 4892 KiB | ||||
35 | Runtime error | 2ms | 4980 KiB | ||||
36 | Runtime error | 3ms | 5064 KiB | ||||
37 | Runtime error | 3ms | 5060 KiB | ||||
38 | Runtime error | 3ms | 5068 KiB | ||||
39 | Runtime error | 3ms | 5060 KiB | ||||
40 | Runtime error | 3ms | 5168 KiB | ||||
41 | Runtime error | 3ms | 5292 KiB | ||||
42 | Runtime error | 3ms | 5396 KiB | ||||
43 | Runtime error | 3ms | 5524 KiB | ||||
44 | Runtime error | 3ms | 5400 KiB | ||||
45 | Runtime error | 3ms | 5296 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 3ms | 5164 KiB | ||||
47 | Runtime error | 2ms | 5164 KiB | ||||
48 | Runtime error | 2ms | 5268 KiB | ||||
49 | Runtime error | 3ms | 5268 KiB | ||||
50 | Runtime error | 3ms | 5064 KiB | ||||
51 | Runtime error | 3ms | 4964 KiB | ||||
52 | Runtime error | 3ms | 5060 KiB | ||||
53 | Runtime error | 3ms | 5068 KiB | ||||
54 | Runtime error | 3ms | 5168 KiB | ||||
55 | Runtime error | 3ms | 5168 KiB |