12582022-03-29 11:34:27vandrasNövekvő Ödön és a Másoló Varázslócpp14Time limit exceeded 25/100695ms63672 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];
vector<int> vals;

int get(int v){
	return lower_bound(vals.begin(), vals.end(), v) - vals.begin();
}

int cnt_between(int l, int r){
//	debug() << exp(lower_bound(b+1, b+m+1, l) - b) exp(l);
	return lower_bound(b+1, b+m+1, r) - lower_bound(b+1, b+m+1, l);
}

int main()
{
	FAST;
	cin >> n >> m;
	vals.resize(n+m);
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		vals[i-1] = a[i];
	}
	for(int i = 1; i <= m; ++i){
		cin >> b[i];
		vals[n+i-1] = b[i];
	}

	sort(vals.begin(), vals.end());

	a[0] = -1;
	for(int i = 1; i <= n; ++i) a[i] = get(a[i]);
	for(int i = 1; i <= m; ++i) b[i] = get(b[i]);

	sort(b+1, b+m+1);

	int mxN = vals.size();

	//dp[i] : best solution up to ith element (ith is left unchanged)

	dp[0] = 0;
	dp[1] = 0;


	a[n+1] = INF;
	for(int i = 2; i <= n+1; ++i){
		dp[i] = INF;
		for(int j = i-1; j >= 0; --j){
			if(dp[j] < INF && a[j] < a[i] && cnt_between(a[j], a[i]) >= i-j-1){
				dp[i] = min(dp[i], dp[j] + i-j-1);
				break;
			}
		}
	}

	cout << min(dp[n], dp[n+1]) << '\n';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1920 KiB
2Time limit exceeded629ms2940 KiB
subtask25/5
3Accepted90ms7732 KiB
4Accepted87ms9668 KiB
5Accepted90ms11616 KiB
subtask310/10
6Accepted1ms8756 KiB
7Accepted1ms8760 KiB
8Accepted1ms8760 KiB
subtask40/15
9Wrong answer2ms8776 KiB
10Wrong answer2ms8788 KiB
11Wrong answer1ms8796 KiB
12Accepted2ms8796 KiB
subtask55/5
13Accepted9ms9136 KiB
14Accepted14ms9224 KiB
15Accepted10ms9324 KiB
subtask65/5
16Accepted97ms9436 KiB
17Accepted16ms9540 KiB
18Accepted21ms9636 KiB
19Accepted97ms9700 KiB
subtask70/10
20Wrong answer6ms9700 KiB
21Wrong answer128ms9912 KiB
22Accepted141ms10008 KiB
23Wrong answer32ms9988 KiB
24Wrong answer48ms10168 KiB
subtask80/25
25Time limit exceeded654ms12596 KiB
26Time limit exceeded614ms12296 KiB
27Time limit exceeded630ms14240 KiB
28Accepted1ms13488 KiB
29Time limit exceeded615ms16272 KiB
30Wrong answer108ms21264 KiB
31Wrong answer331ms23188 KiB
32Time limit exceeded651ms21928 KiB
33Time limit exceeded674ms19680 KiB
34Time limit exceeded695ms21428 KiB
35Time limit exceeded689ms23440 KiB
36Wrong answer337ms28380 KiB
37Time limit exceeded685ms27484 KiB
38Time limit exceeded657ms29224 KiB
39Time limit exceeded695ms31048 KiB
40Time limit exceeded694ms33064 KiB
41Time limit exceeded666ms34928 KiB
42Wrong answer119ms37724 KiB
43Wrong answer89ms41172 KiB
44Time limit exceeded685ms40216 KiB
45Time limit exceeded694ms41952 KiB
subtask90/25
46Time limit exceeded648ms42960 KiB
47Time limit exceeded694ms41944 KiB
48Time limit exceeded694ms46524 KiB
49Time limit exceeded671ms49756 KiB
50Time limit exceeded676ms48368 KiB
51Time limit exceeded691ms49464 KiB
52Time limit exceeded694ms52416 KiB
53Time limit exceeded695ms56292 KiB
54Time limit exceeded666ms60288 KiB
55Time limit exceeded680ms63672 KiB