10034 | 2024-03-25 16:25:46 | 111 | Növekvő Ödön és a Másoló Varázsló | cpp17 | Wrong answer 0/100 | 384ms | 524672 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;
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?INT_MAX: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();
if(j>0){
ans[i]=dp[i][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 | Wrong answer | 3ms | 1860 KiB | ||||
2 | Runtime error | 209ms | 524672 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Accepted | 61ms | 20084 KiB | ||||
4 | Wrong answer | 61ms | 22120 KiB | ||||
5 | Wrong answer | 61ms | 24060 KiB | ||||
subtask3 | 0/10 | ||||||
6 | Wrong answer | 3ms | 8676 KiB | ||||
7 | Wrong answer | 3ms | 8696 KiB | ||||
8 | Wrong answer | 2ms | 8700 KiB | ||||
subtask4 | 0/15 | ||||||
9 | Wrong answer | 3ms | 10160 KiB | ||||
10 | Wrong answer | 4ms | 10436 KiB | ||||
11 | Wrong answer | 4ms | 10280 KiB | ||||
12 | Wrong answer | 3ms | 10692 KiB | ||||
subtask5 | 0/5 | ||||||
13 | Wrong answer | 261ms | 401148 KiB | ||||
14 | Wrong answer | 261ms | 401548 KiB | ||||
15 | Wrong answer | 261ms | 401548 KiB | ||||
subtask6 | 0/5 | ||||||
16 | Wrong answer | 244ms | 401640 KiB | ||||
17 | Wrong answer | 194ms | 401736 KiB | ||||
18 | Wrong answer | 216ms | 401836 KiB | ||||
19 | Wrong answer | 225ms | 401992 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Wrong answer | 209ms | 402088 KiB | ||||
21 | Wrong answer | 243ms | 402188 KiB | ||||
22 | Wrong answer | 243ms | 402504 KiB | ||||
23 | Wrong answer | 92ms | 152004 KiB | ||||
24 | Wrong answer | 202ms | 383788 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 231ms | 522356 KiB | ||||
26 | Runtime error | 266ms | 522332 KiB | ||||
27 | Runtime error | 224ms | 522320 KiB | ||||
28 | Accepted | 3ms | 4484 KiB | ||||
29 | Runtime error | 224ms | 522284 KiB | ||||
30 | Runtime error | 219ms | 522276 KiB | ||||
31 | Runtime error | 266ms | 522020 KiB | ||||
32 | Runtime error | 219ms | 521896 KiB | ||||
33 | Runtime error | 224ms | 521880 KiB | ||||
34 | Runtime error | 266ms | 521864 KiB | ||||
35 | Runtime error | 222ms | 521616 KiB | ||||
36 | Runtime error | 222ms | 521616 KiB | ||||
37 | Runtime error | 223ms | 521624 KiB | ||||
38 | Runtime error | 268ms | 521616 KiB | ||||
39 | Runtime error | 225ms | 521604 KiB | ||||
40 | Runtime error | 268ms | 521364 KiB | ||||
41 | Runtime error | 224ms | 521356 KiB | ||||
42 | Runtime error | 206ms | 521356 KiB | ||||
43 | Runtime error | 266ms | 521340 KiB | ||||
44 | Runtime error | 225ms | 521320 KiB | ||||
45 | Runtime error | 225ms | 521320 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 294ms | 521304 KiB | ||||
47 | Runtime error | 298ms | 521296 KiB | ||||
48 | Runtime error | 300ms | 521292 KiB | ||||
49 | Runtime error | 294ms | 521300 KiB | ||||
50 | Runtime error | 293ms | 521272 KiB | ||||
51 | Runtime error | 298ms | 521260 KiB | ||||
52 | Runtime error | 287ms | 521264 KiB | ||||
53 | Runtime error | 298ms | 521256 KiB | ||||
54 | Runtime error | 303ms | 521256 KiB | ||||
55 | Runtime error | 384ms | 521012 KiB |