1267 | 2022-03-29 12:32:25 | vandras | Növekvő Ödön és a Másoló Varázsló | cpp14 | Time limit exceeded 50/100 | 697ms | 64436 KiB |
#include <bits/stdc++.h>
using namespace std;
/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; }
struct debug{
#ifdef _LOCAL
~debug(){ cerr << endl; }
tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
tem T, typename U > _op (pair<T, U> i){
return *this << "< " << i.first << " , " << i.second << " >"; }
tem T> _op (itr<T> i){
*this << "{ ";
for(auto it = i.begin; it != i.end; it++){
*this << " , " + (it==i.begin?2:0) << *it;
}
return *this << " }";
}
#else
tem T> _op (const T&) { return *this; }
#endif
};
tem T>
string _ARR_(T* arr, int sz){
string ret = "{ " + to_string(arr[0]);
for(int i = 1; i < sz; i++) ret += " , " + to_string(arr[i]);
ret += " }"; return ret;
}
#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> pii;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)
#define ar array
const int INF = 1e9 + 7, N = 200005, M = 5003;
int a[N], b[N], n, m, dp[N];
int main()
{
FAST;
cin >> n >> m;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= m; ++i){
cin >> b[i];
}
sort(b+1, b+m+1);
//dp[i] : best solution up to ith element (ith is left unchanged)
a[0] = -1;
a[n+1] = INF;
dp[0] = 0;
dp[1] = 0;
for(int i = 2; i <= n+1; ++i){
dp[i] = INF;
int bpos = lower_bound(b+1, b+m+1, a[i])-b-1;
if(a[i-1] < a[i]){
dp[i] = dp[i-1];
}
for(int j = i-1; j > 0 && bpos > 0; --j, --bpos){
if(a[j-1] < b[bpos]){
dp[i] = min(dp[i], dp[j-1] + (i-j));
}
}
}
cout << min(dp[n], dp[n+1]) << '\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 1944 KiB | ||||
2 | Time limit exceeded | 652ms | 2580 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 43ms | 6484 KiB | ||||
4 | Accepted | 41ms | 8428 KiB | ||||
5 | Accepted | 41ms | 10400 KiB | ||||
subtask3 | 10/10 | ||||||
6 | Accepted | 1ms | 8816 KiB | ||||
7 | Accepted | 1ms | 8820 KiB | ||||
8 | Accepted | 1ms | 8804 KiB | ||||
subtask4 | 15/15 | ||||||
9 | Accepted | 1ms | 8812 KiB | ||||
10 | Accepted | 1ms | 8816 KiB | ||||
11 | Accepted | 1ms | 8852 KiB | ||||
12 | Accepted | 2ms | 8868 KiB | ||||
subtask5 | 5/5 | ||||||
13 | Accepted | 3ms | 9044 KiB | ||||
14 | Accepted | 3ms | 9144 KiB | ||||
15 | Accepted | 3ms | 9236 KiB | ||||
subtask6 | 5/5 | ||||||
16 | Accepted | 27ms | 9396 KiB | ||||
17 | Accepted | 25ms | 9488 KiB | ||||
18 | Accepted | 14ms | 9596 KiB | ||||
19 | Accepted | 21ms | 9664 KiB | ||||
subtask7 | 10/10 | ||||||
20 | Accepted | 37ms | 9768 KiB | ||||
21 | Accepted | 32ms | 9880 KiB | ||||
22 | Accepted | 39ms | 9968 KiB | ||||
23 | Accepted | 13ms | 9992 KiB | ||||
24 | Accepted | 32ms | 10128 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Time limit exceeded | 609ms | 11960 KiB | ||||
26 | Time limit exceeded | 611ms | 13892 KiB | ||||
27 | Time limit exceeded | 642ms | 15808 KiB | ||||
28 | Accepted | 1ms | 15788 KiB | ||||
29 | Time limit exceeded | 615ms | 17632 KiB | ||||
30 | Time limit exceeded | 669ms | 19696 KiB | ||||
31 | Time limit exceeded | 676ms | 21552 KiB | ||||
32 | Time limit exceeded | 689ms | 23452 KiB | ||||
33 | Time limit exceeded | 693ms | 25420 KiB | ||||
34 | Time limit exceeded | 694ms | 27252 KiB | ||||
35 | Time limit exceeded | 657ms | 29296 KiB | ||||
36 | Time limit exceeded | 697ms | 31196 KiB | ||||
37 | Time limit exceeded | 694ms | 33132 KiB | ||||
38 | Time limit exceeded | 693ms | 35056 KiB | ||||
39 | Time limit exceeded | 693ms | 36928 KiB | ||||
40 | Time limit exceeded | 695ms | 38856 KiB | ||||
41 | Time limit exceeded | 690ms | 40856 KiB | ||||
42 | Time limit exceeded | 691ms | 41668 KiB | ||||
43 | Time limit exceeded | 695ms | 44040 KiB | ||||
44 | Time limit exceeded | 683ms | 45908 KiB | ||||
45 | Time limit exceeded | 693ms | 47852 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Time limit exceeded | 680ms | 52492 KiB | ||||
47 | Time limit exceeded | 677ms | 54468 KiB | ||||
48 | Time limit exceeded | 677ms | 48016 KiB | ||||
49 | Time limit exceeded | 674ms | 51960 KiB | ||||
50 | Time limit exceeded | 670ms | 55896 KiB | ||||
51 | Time limit exceeded | 697ms | 59716 KiB | ||||
52 | Time limit exceeded | 676ms | 56064 KiB | ||||
53 | Time limit exceeded | 690ms | 56620 KiB | ||||
54 | Time limit exceeded | 693ms | 60604 KiB | ||||
55 | Time limit exceeded | 601ms | 64436 KiB |