1264 | 2022-03-29 12:04:10 | vandras | Növekvő Ödön és a Másoló Varázsló | cpp14 | Time limit exceeded 0/100 | 695ms | 73524 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;
for(int j = i-1; j > 0 && bpos > 0; --j, --bpos){
if(a[j-1] < b[bpos] && dp[j-1] < INF){
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 | 3ms | 1980 KiB | ||||
2 | Time limit exceeded | 635ms | 2568 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Wrong answer | 43ms | 6492 KiB | ||||
4 | Accepted | 43ms | 8436 KiB | ||||
5 | Accepted | 43ms | 10392 KiB | ||||
subtask3 | 0/10 | ||||||
6 | Accepted | 2ms | 8824 KiB | ||||
7 | Accepted | 1ms | 8828 KiB | ||||
8 | Wrong answer | 1ms | 8832 KiB | ||||
subtask4 | 0/15 | ||||||
9 | Wrong answer | 1ms | 8844 KiB | ||||
10 | Wrong answer | 2ms | 8844 KiB | ||||
11 | Wrong answer | 2ms | 8828 KiB | ||||
12 | Accepted | 2ms | 8836 KiB | ||||
subtask5 | 0/5 | ||||||
13 | Wrong answer | 3ms | 9036 KiB | ||||
14 | Accepted | 3ms | 9168 KiB | ||||
15 | Wrong answer | 3ms | 9256 KiB | ||||
subtask6 | 0/5 | ||||||
16 | Accepted | 39ms | 9384 KiB | ||||
17 | Wrong answer | 35ms | 9496 KiB | ||||
18 | Wrong answer | 14ms | 9584 KiB | ||||
19 | Accepted | 21ms | 9664 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Wrong answer | 41ms | 9776 KiB | ||||
21 | Wrong answer | 43ms | 9864 KiB | ||||
22 | Accepted | 68ms | 9976 KiB | ||||
23 | Wrong answer | 28ms | 9980 KiB | ||||
24 | Wrong answer | 67ms | 10128 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Time limit exceeded | 634ms | 11820 KiB | ||||
26 | Time limit exceeded | 610ms | 13760 KiB | ||||
27 | Time limit exceeded | 602ms | 15760 KiB | ||||
28 | Accepted | 1ms | 15816 KiB | ||||
29 | Time limit exceeded | 666ms | 17640 KiB | ||||
30 | Time limit exceeded | 691ms | 19628 KiB | ||||
31 | Time limit exceeded | 665ms | 21556 KiB | ||||
32 | Time limit exceeded | 693ms | 23496 KiB | ||||
33 | Time limit exceeded | 688ms | 25368 KiB | ||||
34 | Time limit exceeded | 694ms | 27312 KiB | ||||
35 | Time limit exceeded | 663ms | 29276 KiB | ||||
36 | Time limit exceeded | 690ms | 31196 KiB | ||||
37 | Time limit exceeded | 619ms | 33128 KiB | ||||
38 | Time limit exceeded | 695ms | 35048 KiB | ||||
39 | Time limit exceeded | 629ms | 36992 KiB | ||||
40 | Time limit exceeded | 660ms | 38848 KiB | ||||
41 | Time limit exceeded | 671ms | 40804 KiB | ||||
42 | Time limit exceeded | 695ms | 41820 KiB | ||||
43 | Time limit exceeded | 683ms | 43908 KiB | ||||
44 | Time limit exceeded | 675ms | 45848 KiB | ||||
45 | Time limit exceeded | 695ms | 47968 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Time limit exceeded | 690ms | 52488 KiB | ||||
47 | Time limit exceeded | 694ms | 56360 KiB | ||||
48 | Time limit exceeded | 691ms | 60228 KiB | ||||
49 | Time limit exceeded | 695ms | 64104 KiB | ||||
50 | Time limit exceeded | 694ms | 67984 KiB | ||||
51 | Time limit exceeded | 694ms | 71920 KiB | ||||
52 | Time limit exceeded | 677ms | 73524 KiB | ||||
53 | Time limit exceeded | 670ms | 62288 KiB | ||||
54 | Time limit exceeded | 694ms | 66208 KiB | ||||
55 | Time limit exceeded | 677ms | 70036 KiB |