1263 | 2022-03-29 12:03:20 | vandras | Növekvő Ödön és a Másoló Varázsló | cpp14 | Time limit exceeded 0/100 | 699ms | 5352 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;
debug() << exp(a[i]) exp(b[bpos]) exp(bpos);
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 | 1904 KiB | ||||
2 | Time limit exceeded | 699ms | 1820 KiB | ||||
subtask2 | 0/5 | ||||||
3 | Wrong answer | 46ms | 3716 KiB | ||||
4 | Accepted | 46ms | 4044 KiB | ||||
5 | Accepted | 46ms | 4052 KiB | ||||
subtask3 | 0/10 | ||||||
6 | Accepted | 2ms | 2376 KiB | ||||
7 | Accepted | 2ms | 2584 KiB | ||||
8 | Wrong answer | 2ms | 2712 KiB | ||||
subtask4 | 0/15 | ||||||
9 | Wrong answer | 2ms | 2796 KiB | ||||
10 | Wrong answer | 2ms | 3120 KiB | ||||
11 | Wrong answer | 2ms | 3000 KiB | ||||
12 | Accepted | 2ms | 2996 KiB | ||||
subtask5 | 0/5 | ||||||
13 | Wrong answer | 4ms | 3056 KiB | ||||
14 | Accepted | 4ms | 3332 KiB | ||||
15 | Wrong answer | 4ms | 3256 KiB | ||||
subtask6 | 0/5 | ||||||
16 | Accepted | 43ms | 3256 KiB | ||||
17 | Wrong answer | 18ms | 3252 KiB | ||||
18 | Wrong answer | 16ms | 3536 KiB | ||||
19 | Accepted | 17ms | 3480 KiB | ||||
subtask7 | 0/10 | ||||||
20 | Wrong answer | 24ms | 3628 KiB | ||||
21 | Wrong answer | 27ms | 3492 KiB | ||||
22 | Accepted | 50ms | 3464 KiB | ||||
23 | Wrong answer | 16ms | 3432 KiB | ||||
24 | Wrong answer | 32ms | 3456 KiB | ||||
subtask8 | 0/25 | ||||||
25 | Time limit exceeded | 663ms | 3716 KiB | ||||
26 | Time limit exceeded | 642ms | 3736 KiB | ||||
27 | Time limit exceeded | 629ms | 3628 KiB | ||||
28 | Accepted | 2ms | 3684 KiB | ||||
29 | Time limit exceeded | 699ms | 3424 KiB | ||||
30 | Time limit exceeded | 658ms | 3552 KiB | ||||
31 | Time limit exceeded | 662ms | 3676 KiB | ||||
32 | Time limit exceeded | 662ms | 3700 KiB | ||||
33 | Time limit exceeded | 653ms | 3820 KiB | ||||
34 | Time limit exceeded | 662ms | 3820 KiB | ||||
35 | Time limit exceeded | 677ms | 3840 KiB | ||||
36 | Time limit exceeded | 662ms | 3972 KiB | ||||
37 | Time limit exceeded | 657ms | 4188 KiB | ||||
38 | Time limit exceeded | 674ms | 4148 KiB | ||||
39 | Time limit exceeded | 662ms | 4228 KiB | ||||
40 | Time limit exceeded | 674ms | 4452 KiB | ||||
41 | Time limit exceeded | 657ms | 4548 KiB | ||||
42 | Time limit exceeded | 657ms | 4108 KiB | ||||
43 | Time limit exceeded | 681ms | 4252 KiB | ||||
44 | Time limit exceeded | 683ms | 4380 KiB | ||||
45 | Time limit exceeded | 674ms | 4312 KiB | ||||
subtask9 | 0/25 | ||||||
46 | Time limit exceeded | 638ms | 5232 KiB | ||||
47 | Time limit exceeded | 671ms | 5048 KiB | ||||
48 | Time limit exceeded | 658ms | 5192 KiB | ||||
49 | Time limit exceeded | 657ms | 4976 KiB | ||||
50 | Time limit exceeded | 666ms | 5196 KiB | ||||
51 | Time limit exceeded | 671ms | 5124 KiB | ||||
52 | Time limit exceeded | 666ms | 5060 KiB | ||||
53 | Time limit exceeded | 665ms | 5188 KiB | ||||
54 | Time limit exceeded | 666ms | 5204 KiB | ||||
55 | Time limit exceeded | 666ms | 5352 KiB |