답안 #747397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747397 2023-05-24T06:53:14 Z vjudge1 Kralj (COCI16_kralj) C++17
0 / 140
2000 ms 77836 KB
#include <bits/stdc++.h>
#include <array>
#define all(v) (v.begin()), (v.end())
#define setall(a, val) for(auto& x : a) x = val
#define ll long long
#define cerr (cerr << "D: ")
clock_t start_time;
using namespace std;
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
void init(bool oj = 1) {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	srand(time(0)); start_time = clock();
	if (oj) {
#ifndef ONLINE_JUDGE
		FILE* _ = freopen("in.txt", "r", stdin);
		//FILE* __ = freopen("out.txt", "w", stdout);
#endif
	}
}
const ll MOD = 1e9 + 7;
const ll N = 5e5 + 7;
const ll M = 2e3 + 7;
//####################################################################################

int n;
bool vis[N];
vector<int> a;
multiset<int> b;

int solve(int i) {
	if (i == n)
		return 0;

	int mx = 0, f = *b.begin();
	b.erase(b.begin());
	mx = max(mx, solve(i + 1) + (f > a[i]));
	b.insert(f);

	auto it = b.lower_bound(a[i]);
	if (it == b.end())
		return mx;

	f = *it;
	b.erase(it);
	mx = max(mx, solve(i + 1) + (f > a[i]));
	b.insert(f);

	it = b.upper_bound(a[i]);
	if (it == b.end())
		return mx;

	f = *it;
	b.erase(it);
	mx = max(mx, solve(i + 1) + (f > a[i]));
	b.insert(f);

	return mx;
}

int main() {
	init(0);

	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {int _; cin >> _;}
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		b.insert(x);
	}

	cout << solve(0) << endl;

	cerr << get_time() << "s" << endl;
}

Compilation message

kralj.cpp: In function 'void init(bool)':
kralj.cpp:15:9: warning: unused variable '_' [-Wunused-variable]
   15 |   FILE* _ = freopen("in.txt", "r", stdin);
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2054 ms 60620 KB Time limit exceeded
2 Execution timed out 2064 ms 58700 KB Time limit exceeded
3 Execution timed out 2070 ms 73136 KB Time limit exceeded
4 Execution timed out 2057 ms 74444 KB Time limit exceeded
5 Execution timed out 2059 ms 70572 KB Time limit exceeded
6 Execution timed out 2061 ms 69660 KB Time limit exceeded
7 Execution timed out 2049 ms 73360 KB Time limit exceeded
8 Execution timed out 2066 ms 65848 KB Time limit exceeded
9 Execution timed out 2036 ms 77836 KB Time limit exceeded
10 Execution timed out 2059 ms 77040 KB Time limit exceeded