1235 | 2022-03-27 18:41:28 | Valaki2 | Növekvő Ödön és a Másoló Varázsló | cpp14 | Runtime error 20/100 | 603ms | 488992 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 + n, 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 | 3ms | 1936 KiB | ||||
2 | Runtime error | 282ms | 444332 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Runtime error | 4ms | 2568 KiB | ||||
4 | Runtime error | 4ms | 3096 KiB | ||||
5 | Runtime error | 4ms | 3588 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 1ms | 3372 KiB | ||||
7 | Accepted | 1ms | 3372 KiB | ||||
8 | Accepted | 1ms | 3380 KiB | ||||
subtask4 | 0/15 | ||||||
9 | Accepted | 3ms | 4088 KiB | ||||
10 | Accepted | 4ms | 4096 KiB | ||||
11 | Runtime error | 2ms | 3524 KiB | ||||
12 | Accepted | 3ms | 4116 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 374ms | 199380 KiB | ||||
14 | Accepted | 356ms | 199432 KiB | ||||
15 | Accepted | 363ms | 199536 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 363ms | 199636 KiB | ||||
17 | Accepted | 375ms | 199704 KiB | ||||
18 | Accepted | 358ms | 199832 KiB | ||||
19 | Accepted | 360ms | 199936 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Time limit exceeded | 603ms | 200004 KiB | ||||
21 | Accepted | 564ms | 200104 KiB | ||||
22 | Accepted | 379ms | 200204 KiB | ||||
23 | Accepted | 196ms | 75020 KiB | ||||
24 | Runtime error | 3ms | 4736 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Runtime error | 356ms | 456616 KiB | ||||
26 | Runtime error | 261ms | 456684 KiB | ||||
27 | Runtime error | 261ms | 457024 KiB | ||||
28 | Accepted | 1ms | 1900 KiB | ||||
29 | Runtime error | 259ms | 456988 KiB | ||||
30 | Runtime error | 240ms | 456244 KiB | ||||
31 | Runtime error | 244ms | 453936 KiB | ||||
32 | Runtime error | 247ms | 456884 KiB | ||||
33 | Runtime error | 263ms | 470180 KiB | ||||
34 | Runtime error | 256ms | 477024 KiB | ||||
35 | Runtime error | 248ms | 483016 KiB | ||||
36 | Runtime error | 270ms | 483424 KiB | ||||
37 | Runtime error | 307ms | 483152 KiB | ||||
38 | Runtime error | 317ms | 482864 KiB | ||||
39 | Runtime error | 266ms | 486844 KiB | ||||
40 | Runtime error | 256ms | 485336 KiB | ||||
41 | Runtime error | 256ms | 488992 KiB | ||||
42 | Runtime error | 250ms | 483396 KiB | ||||
43 | Runtime error | 248ms | 456968 KiB | ||||
44 | Runtime error | 252ms | 448812 KiB | ||||
45 | Runtime error | 240ms | 457548 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Runtime error | 300ms | 482920 KiB | ||||
47 | Runtime error | 286ms | 399692 KiB | ||||
48 | Runtime error | 328ms | 472920 KiB | ||||
49 | Runtime error | 280ms | 461448 KiB | ||||
50 | Runtime error | 293ms | 482460 KiB | ||||
51 | Runtime error | 284ms | 457584 KiB | ||||
52 | Runtime error | 284ms | 473784 KiB | ||||
53 | Runtime error | 268ms | 456416 KiB | ||||
54 | Runtime error | 305ms | 475152 KiB | ||||
55 | Runtime error | 282ms | 466392 KiB |