1236 | 2022-03-27 18:43:59 | Valaki2 | Növekvő Ödön és a Másoló Varázsló | cpp14 | Runtime error 50/100 | 598ms | 473728 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int inf = 1e9 + 7;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(1 + n, 0);
vector<int> b(1 + m, 0);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
for(int i = 1; i <= m; i++) {
cin >> b[i];
}
sort(b.begin() + 1, b.end());
vector<int> req(1 + n, inf);
// req[i]: minimum hany valtoztatas kell mindenkepp (az elso i elemen ertelmezve)
vector<vector<int> > dp(1 + n, vector<int> (1 + n, inf));
// dp[i][j]: max j darab valtoztatassal mi a legkisebb maximum (az elso i elemen ertelmezve)
// dp[i] csokkeno
for(int j = 0; j <= n; j++) {
dp[0][j] = 0;
}
req[0] = 0;
for(int i = 1; i <= n; i++) {
for(int j = req[i - 1]; j <= n; j++) {
if(dp[i - 1][j] < a[i]) {
dp[i][j] = a[i];
}
}
for(int j = req[i - 1]; j < n; j++) {
auto it = upper_bound(b.begin(), b.end(), dp[i - 1][j]);
if(it == b.end()) {
continue;
}
int num = *it;
dp[i][j + 1] = min(dp[i][j + 1], num);
}
for(int j = 0; j <= n; j++) {
if(dp[i][j] != inf) {
req[i] = j;
break;
}
}
}
cout << req[n] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 2028 KiB | ||||
2 | Runtime error | 241ms | 445392 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 45ms | 5216 KiB | ||||
4 | Accepted | 43ms | 7156 KiB | ||||
5 | Accepted | 41ms | 9112 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 1ms | 7756 KiB | ||||
7 | Accepted | 1ms | 7760 KiB | ||||
8 | Accepted | 1ms | 7784 KiB | ||||
subtask4 | 15/15 | ||||||
9 | Accepted | 3ms | 8476 KiB | ||||
10 | Accepted | 3ms | 8480 KiB | ||||
11 | Accepted | 2ms | 8184 KiB | ||||
12 | Accepted | 2ms | 8496 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 363ms | 202392 KiB | ||||
14 | Accepted | 361ms | 198848 KiB | ||||
15 | Accepted | 361ms | 198952 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 358ms | 199088 KiB | ||||
17 | Accepted | 363ms | 199244 KiB | ||||
18 | Accepted | 365ms | 199304 KiB | ||||
19 | Accepted | 360ms | 199384 KiB | ||||
subtask7 | 10/10 | ||||||
20 | Accepted | 598ms | 199476 KiB | ||||
21 | Accepted | 555ms | 199564 KiB | ||||
22 | Accepted | 374ms | 199664 KiB | ||||
23 | Accepted | 167ms | 74480 KiB | ||||
24 | Accepted | 483ms | 181244 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 240ms | 456312 KiB | ||||
26 | Runtime error | 246ms | 456504 KiB | ||||
27 | Runtime error | 248ms | 456488 KiB | ||||
28 | Accepted | 1ms | 1948 KiB | ||||
29 | Runtime error | 273ms | 455672 KiB | ||||
30 | Runtime error | 250ms | 456292 KiB | ||||
31 | Runtime error | 250ms | 457752 KiB | ||||
32 | Runtime error | 259ms | 461436 KiB | ||||
33 | Runtime error | 259ms | 469896 KiB | ||||
34 | Runtime error | 263ms | 473716 KiB | ||||
35 | Runtime error | 246ms | 473728 KiB | ||||
36 | Runtime error | 247ms | 471836 KiB | ||||
37 | Runtime error | 248ms | 473032 KiB | ||||
38 | Runtime error | 256ms | 473020 KiB | ||||
39 | Runtime error | 257ms | 472816 KiB | ||||
40 | Runtime error | 254ms | 473092 KiB | ||||
41 | Runtime error | 261ms | 472864 KiB | ||||
42 | Runtime error | 239ms | 473344 KiB | ||||
43 | Runtime error | 261ms | 472972 KiB | ||||
44 | Runtime error | 245ms | 470276 KiB | ||||
45 | Runtime error | 250ms | 473080 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 282ms | 473116 KiB | ||||
47 | Runtime error | 284ms | 472916 KiB | ||||
48 | Runtime error | 397ms | 471540 KiB | ||||
49 | Runtime error | 284ms | 472944 KiB | ||||
50 | Runtime error | 305ms | 470664 KiB | ||||
51 | Runtime error | 284ms | 473508 KiB | ||||
52 | Runtime error | 272ms | 473092 KiB | ||||
53 | Runtime error | 284ms | 473424 KiB | ||||
54 | Runtime error | 282ms | 473696 KiB | ||||
55 | Runtime error | 289ms | 473136 KiB |