12572022-03-29 11:32:58vandrasNövekvő Ödön és a Másoló Varázslócpp14Time limit exceeded 40/100697ms62488 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(a[j] < a[i] && cnt_between(a[j], a[i]) >= i-j-1) dp[i] = min(dp[i], dp[j] + i-j-1);
		}
	}

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

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1924 KiB
2Time limit exceeded693ms2800 KiB
subtask25/5
3Accepted90ms7732 KiB
4Accepted93ms9660 KiB
5Accepted90ms11604 KiB
subtask310/10
6Accepted1ms8744 KiB
7Accepted1ms8756 KiB
8Accepted1ms8756 KiB
subtask415/15
9Accepted3ms8772 KiB
10Accepted3ms8776 KiB
11Accepted3ms8784 KiB
12Accepted3ms8788 KiB
subtask55/5
13Accepted270ms9120 KiB
14Accepted275ms9220 KiB
15Accepted294ms9324 KiB
subtask65/5
16Accepted268ms9428 KiB
17Accepted439ms9520 KiB
18Accepted395ms9624 KiB
19Accepted259ms9692 KiB
subtask70/10
20Time limit exceeded661ms8752 KiB
21Time limit exceeded681ms8792 KiB
22Time limit exceeded680ms9988 KiB
23Accepted268ms9984 KiB
24Time limit exceeded691ms9048 KiB
subtask80/25
25Time limit exceeded694ms12700 KiB
26Time limit exceeded694ms14580 KiB
27Time limit exceeded694ms16648 KiB
28Accepted1ms15736 KiB
29Time limit exceeded694ms18476 KiB
30Time limit exceeded665ms20420 KiB
31Time limit exceeded603ms22248 KiB
32Time limit exceeded601ms24108 KiB
33Time limit exceeded605ms21196 KiB
34Time limit exceeded625ms23068 KiB
35Time limit exceeded606ms25064 KiB
36Time limit exceeded649ms27004 KiB
37Time limit exceeded652ms28944 KiB
38Time limit exceeded605ms24264 KiB
39Time limit exceeded693ms26192 KiB
40Time limit exceeded694ms28108 KiB
41Time limit exceeded695ms30032 KiB
42Time limit exceeded671ms30640 KiB
43Time limit exceeded694ms33108 KiB
44Time limit exceeded697ms35044 KiB
45Time limit exceeded693ms37100 KiB
subtask90/25
46Time limit exceeded694ms42476 KiB
47Time limit exceeded675ms46344 KiB
48Time limit exceeded685ms47204 KiB
49Time limit exceeded694ms44028 KiB
50Time limit exceeded694ms47844 KiB
51Time limit exceeded689ms51720 KiB
52Time limit exceeded694ms54672 KiB
53Time limit exceeded695ms58496 KiB
54Time limit exceeded694ms62488 KiB
55Time limit exceeded689ms62416 KiB