Submission #747399

# Submission time Handle Problem Language Result Execution time Memory
747399 2023-05-24T06:55:06 Z vjudge1 Kralj (COCI16_kralj) C++17
0 / 140
3 ms 340 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();

	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);
	}
	sort(all(a));
	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);
      |         ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Incorrect 3 ms 340 KB Output isn't correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Incorrect 2 ms 340 KB Output isn't correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 2 ms 340 KB Output isn't correct
10 Incorrect 2 ms 340 KB Output isn't correct