10037 | 2024-03-25 16:32:38 | 111 | Növekvő Ödön és a Másoló Varázsló | cpp17 | Runtime error 50/100 | 307ms | 402184 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>100000000){
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 | 1832 KiB | ||||
2 | Runtime error | 3ms | 2056 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 64ms | 19832 KiB | ||||
4 | Accepted | 61ms | 22012 KiB | ||||
5 | Accepted | 59ms | 23888 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 3ms | 8340 KiB | ||||
7 | Accepted | 3ms | 8580 KiB | ||||
8 | Accepted | 3ms | 8748 KiB | ||||
subtask4 | 15/15 | ||||||
9 | Accepted | 3ms | 10036 KiB | ||||
10 | Accepted | 4ms | 10300 KiB | ||||
11 | Accepted | 4ms | 9816 KiB | ||||
12 | Accepted | 4ms | 10464 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 272ms | 400648 KiB | ||||
14 | Accepted | 305ms | 401052 KiB | ||||
15 | Accepted | 307ms | 401332 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 279ms | 401364 KiB | ||||
17 | Accepted | 219ms | 401628 KiB | ||||
18 | Accepted | 293ms | 401600 KiB | ||||
19 | Accepted | 248ms | 401812 KiB | ||||
subtask7 | 10/10 | ||||||
20 | Accepted | 279ms | 401952 KiB | ||||
21 | Accepted | 243ms | 402040 KiB | ||||
22 | Accepted | 239ms | 402184 KiB | ||||
23 | Accepted | 104ms | 151948 KiB | ||||
24 | Accepted | 264ms | 383420 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 3ms | 11208 KiB | ||||
26 | Runtime error | 2ms | 11288 KiB | ||||
27 | Runtime error | 3ms | 11364 KiB | ||||
28 | Accepted | 3ms | 11364 KiB | ||||
29 | Runtime error | 3ms | 11364 KiB | ||||
30 | Runtime error | 3ms | 11364 KiB | ||||
31 | Runtime error | 3ms | 11496 KiB | ||||
32 | Runtime error | 3ms | 11620 KiB | ||||
33 | Runtime error | 3ms | 11720 KiB | ||||
34 | Runtime error | 3ms | 11704 KiB | ||||
35 | Runtime error | 3ms | 11688 KiB | ||||
36 | Runtime error | 3ms | 11812 KiB | ||||
37 | Runtime error | 3ms | 11808 KiB | ||||
38 | Runtime error | 3ms | 11792 KiB | ||||
39 | Runtime error | 2ms | 11692 KiB | ||||
40 | Runtime error | 3ms | 11692 KiB | ||||
41 | Runtime error | 3ms | 11788 KiB | ||||
42 | Runtime error | 3ms | 11780 KiB | ||||
43 | Runtime error | 3ms | 11916 KiB | ||||
44 | Runtime error | 3ms | 12000 KiB | ||||
45 | Runtime error | 3ms | 12004 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 3ms | 12000 KiB | ||||
47 | Runtime error | 2ms | 12000 KiB | ||||
48 | Runtime error | 3ms | 12096 KiB | ||||
49 | Runtime error | 2ms | 12104 KiB | ||||
50 | Runtime error | 2ms | 12204 KiB | ||||
51 | Runtime error | 2ms | 12104 KiB | ||||
52 | Runtime error | 2ms | 12100 KiB | ||||
53 | Runtime error | 2ms | 12004 KiB | ||||
54 | Runtime error | 3ms | 12100 KiB | ||||
55 | Runtime error | 2ms | 12200 KiB |