Submission #1381153


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

struct Edge {
	int from, to;
	Edge(int f, int t) : from(f), to(t) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> kosaraju(const Graph& g) {
	int n = g.size(), sz = 0;
	Graph rg(n);
	vector<int>stk, cmp(n, -1), added(n), visited(n), ord(n);
	for (auto &es : g) {
		for (auto &e : es)rg[e.to].emplace_back(e.to, e.from);
		sz += es.size();
	}
	stk.resize(n + sz);
	sz = 0;
	for (int i = 0; i<n; ++i) {
		if (visited[i])continue;
		int s = 0;
		stk[s++] = i;
		while (s != 0) {
			int v = stk[s - 1];
			visited[v] = true;
			bool pushed = false;
			for (auto &e : g[v]) {
				int to = e.to;
				if (!visited[to]) {
					stk[s++] = to;
					pushed = true;
				}
			}
			if (pushed)continue;
			int t = stk[s - 1];
			if (!added[t]) {
				added[t] = true;
				ord[n - ++sz] = t;
			}
			--s;
		}
	}
	int k = 0;
	for (int &u : ord) {
		if (cmp[u] != -1)continue;
		int s = 0;
		stk[s++] = u;
		while (s != 0) {
			int v = stk[--s];
			cmp[v] = k;
			for (auto &e : rg[v]) {
				int t = e.to;
				if (cmp[t] == -1)stk[s++] = t;
			}
		}
		++k;
	}
	return cmp;
}

int main()
{
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	int l = 0, r = 1e9 + 1;
	while (l + 1 < r) {
		int c = l + (r - l) / 2;
		Graph g(N * 2);
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				if (abs(x[i] - x[j]) < c) {
					g[i].emplace_back(i, N + j);
					g[j].emplace_back(j, N + i);
				}
				if (abs(x[i] - y[j]) < c) {
					g[i].emplace_back(i, j);
					g[N + j].emplace_back(N + j, N + i);
				}
				if (abs(y[i] - x[j]) < c) {
					g[N + i].emplace_back(N + i, N + j);
					g[j].emplace_back(j, i);
				}
				if (abs(y[i] - y[j]) < c) {
					g[N + i].emplace_back(N + i, j);
					g[N + j].emplace_back(N + j, i);
				}
			}
		}
		auto v = kosaraju(g);
		bool can = true;
		for (int i = 0; i < N; i++) {
			if (v[i] == v[i + N]) {
				can = false;
			}
		}
		if (can) {
			l = c;
		}
		else {
			r = c;
		}
	}
	cout << l << endl;
	return 0;
}

Submission Info

Submission Time
Task F - Flags
User kazuma
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2183 Byte
Status TLE
Exec Time 5485 ms
Memory 15872 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1200
Status
AC × 3
AC × 16
TLE × 14
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
00_example_03.txt AC 4 ms 256 KB
01.txt AC 1412 ms 15872 KB
02.txt AC 111 ms 3328 KB
03.txt AC 8 ms 512 KB
04.txt AC 11 ms 640 KB
05.txt AC 14 ms 896 KB
06.txt TLE 5450 ms -1597820 KB
07.txt TLE 5458 ms -1634740 KB
08.txt TLE 5446 ms -1619012 KB
09.txt AC 464 ms 15616 KB
10.txt AC 45 ms 3200 KB
11.txt AC 5 ms 512 KB
12.txt AC 5 ms 640 KB
13.txt AC 7 ms 768 KB
14.txt TLE 5434 ms -1763684 KB
15.txt TLE 5436 ms -1762380 KB
16.txt TLE 5432 ms -1767648 KB
17.txt AC 531 ms 14720 KB
18.txt AC 55 ms 2432 KB
19.txt TLE 5434 ms -1874268 KB
20.txt TLE 5429 ms -1854956 KB
21.txt TLE 5461 ms -1352364 KB
22.txt TLE 5460 ms -1350700 KB
23.txt TLE 5464 ms -1356460 KB
24.txt TLE 5461 ms -1371948 KB
25.txt TLE 5485 ms -1373612 KB
26.txt TLE 5444 ms -1805896 KB
27.txt AC 1 ms 256 KB