Submission #168859

# Submission time Handle Problem Language Result Execution time Memory
168859 2019-12-16T17:19:07 Z Mamnoon_Siam Cipele (COCI18_cipele) C++17
45 / 90
626 ms 9488 KB
#include  <bits/stdc++.h>
using namespace std;

using ll = long long;
using ii = pair<int, int>;

const int maxn = 1e5 + 5;

int n, m;
int a[maxn], b[maxn];
vector<int> g[maxn];
int par[maxn];
int find(int u) {
	return par[u] == u ? u : par[u] = find(par[u]);
}

bool can(int del) {
	for(int i = 1; i <= m; i++) {
		g[i].clear();
	}
	for(int i = 1; i <= n; i++) {
		int l = lower_bound(b + 1, b + 1 + m, a[i] - del) - b;
		int r = upper_bound(b + 1, b + 1 + m, a[i] + del) - b - 1;
		g[r].emplace_back(l);
	}
	iota(par, par + 1 + m + 1, 0);
	for(int r = 1; r <= m; r++) {
		sort(g[r].begin(), g[r].end(), [](int x, int y){
			return x > y;
		});
		for(int l : g[r]) {
			int mn = find(l);
			if(mn > r) {
				return 0;
			} else {
				par[mn] = mn + 1;
			}
		}
	} return 1;
}

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	cin >> n >> m;
	if(n <= m) {
		for(int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		for(int i = 1; i <= m; i++) {
			cin >> b[i];
		}
	} else {
		for(int i = 1; i <= n; i++) {
			cin >> b[i];
		}
		for(int i = 1; i <= m; i++) {
			cin >> a[i];
		}
		swap(n, m);
	}
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + m);
	int lo = 0, hi = 1e9, opt = -1, mid;
	while(lo <= hi) {
		mid = lo + hi >> 1;
		if(can(mid)) {
			opt = mid;
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	cout << opt << endl;
	return 0;
}

Compilation message

cipele.cpp: In function 'int main(int, const char**)':
cipele.cpp:68:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = lo + hi >> 1;
         ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 566 ms 8100 KB Output is correct
2 Correct 605 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 626 ms 9012 KB Output is correct
2 Correct 603 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2808 KB Output is correct
2 Incorrect 18 ms 3952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2680 KB Output is correct
2 Incorrect 18 ms 3952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2936 KB Output is correct
2 Incorrect 18 ms 4060 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2928 KB Output is correct
2 Incorrect 18 ms 3952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2936 KB Output is correct
2 Incorrect 18 ms 3952 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 438 ms 7764 KB Output is correct
2 Correct 342 ms 7660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 529 ms 8532 KB Output is correct
2 Correct 359 ms 8308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 7724 KB Output is correct
2 Correct 511 ms 9488 KB Output is correct