Submission #168840

# Submission time Handle Problem Language Result Execution time Memory
168840 2019-12-16T16:23:52 Z Mamnoon_Siam Cipele (COCI18_cipele) C++17
18 / 90
613 ms 10712 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;
		// cout << l << ' ' << r << endl;
		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 + n);
	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:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = lo + hi >> 1;
         ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 571 ms 9568 KB Output is correct
2 Correct 606 ms 10640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 613 ms 10712 KB Output is correct
2 Correct 601 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2936 KB Output is correct
2 Incorrect 18 ms 4080 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 287 ms 5600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 342 ms 8040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 281 ms 5532 KB Output isn't correct
2 Halted 0 ms 0 KB -