답안 #68057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68057 2018-08-15T20:18:37 Z forestryks Drzava (COCI15_drzava) C++14
136 / 160
1000 ms 62552 KB
///////////////////////////////////////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

// #define int long long

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define f first
#define s second
#define x1 x1qwer
#define y1 y1qwer
#define right right123
#define left left123
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double DINF = numeric_limits<double>::infinity();
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw_(MOD);
uniform_int_distribution<ll> rd_;
ll randomll() { return rd_(mmtw_);}
ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
template <class T> T fact(T n) { if (n == 1) return 1; return n * fact(n - 1); }
////////////////////////////////////////////////////////////////////////////////////////////////

inline ll sqr(ll x) {
	return x * x;
}

const int MAXN = 50005;

struct city {
	long long x, y;
	int k;

	friend bool operator<(const city &a, const city &b) {
		if (a.x == b.x) return a.y < b.y;
		return a.x < b.x;
	}
} a[MAXN];

inline ll dist(int i, int j) {
	return sqr(a[i].x - a[j].x) + sqr(a[i].y - a[j].y);
}

struct cmp {
	bool operator()(const int &i, const int &j) {
		if (a[i].y == a[j].y) return i < j;
		return a[i].y < a[j].y;
	}
};

int n, k;
vector<int> g[MAXN];
set<int, cmp> s;
int dp[MAXN];
bool used[MAXN];

inline int mod(ll x) {
	if (x >= k) return x - k;
	return x;
}

void dfs(int v) {
	used[v] = true;
	if (dp[a[v].k] == -1) dp[a[v].k] = v;
	for (int i = 0; i < k; ++i) {
		if (dp[i] != -1 && dp[i] != v) {
			if (dp[mod(i + a[v].k)] == -1) dp[mod(i + a[v].k)] = v;
		}
	}

	for (auto to : g[v]) {
		if (!used[to]) dfs(to);
	}
}

bool findSet() {
	fill(used, used + n, false);
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;

		fill(dp, dp + k, -1);
		dp[a[i].k] = i;
		dfs(i);
		if (dp[0] != -1) return true;
	}
	return false;
}

bool check(ll d) {
	ll ds = sqrt(d) + 1;
	for (int i = 0; i < n; ++i) {
		g[i].clear();
	}
	s.clear();

	int left = 0;
	for (int i = 0; i < n; ++i) {
		while (sqr(a[i].x - a[left].x) > d) {
			s.erase(left++);
		}

		if (!s.empty()) {
			a[n].y = a[i].y - ds;
			int cnt = 0;
			for (auto it = s.lower_bound(n); it != s.end(); ++it) {
				int id = *it;

				if (a[id].y > a[i].y + ds) break;
				if (++cnt >= k * 8) return true;
				if (dist(i, id) <= d) {
					g[i].push_back(id);
					g[id].push_back(i);
				}
			}
		}

		s.insert(i);
	}

	// rep(v, n) {
	// 	for (auto to : g[v]) {
	// 		cout << "Segment " << a[v].x << ' ' << a[v].y << ' ' << a[to].x << ' ' << a[to].y << '\n';
	// 	}
	// }

	return findSet();
}

int main() {
	FAST_IO;
	cin >> n >> k;
	rep(i, n) {
		cin >> a[i].x >> a[i].y >> a[i].k;
		a[i].k %= k;
	}
	sort(a, a + n);

	// check(4);


	ll e18 = 1e18;
	ll l = -1, r = e18;
	while (r - l > 1) {
		ll m = l + (r - l) / 2;
		if (check(m)) {
			r = m;
		} else {
			l = m;
		}
	}

	if (r == e18) {
		// cout << -1 << endl;
		cout << "No solution!" << endl;
	} else {
		cout.precision(3);
		cout.setf(ios::fixed);
		cout << sqrt(r) << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1528 KB Output is correct
2 Correct 5 ms 1720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1724 KB Output is correct
2 Correct 6 ms 1724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1724 KB Output is correct
2 Correct 19 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2496 KB Output is correct
2 Correct 12 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2496 KB Output is correct
2 Correct 22 ms 2496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2496 KB Output is correct
2 Correct 25 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2900 KB Output is correct
2 Correct 18 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2900 KB Output is correct
2 Correct 13 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2900 KB Output is correct
2 Correct 170 ms 7184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7184 KB Output is correct
2 Execution timed out 1085 ms 55632 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 55632 KB Output is correct
2 Execution timed out 1079 ms 56028 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 56028 KB Output is correct
2 Correct 834 ms 56028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 56028 KB Output is correct
2 Correct 954 ms 56028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 56028 KB Output is correct
2 Execution timed out 1088 ms 62552 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 62552 KB Output is correct
2 Correct 417 ms 62552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 62552 KB Output is correct
2 Correct 633 ms 62552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 62552 KB Output is correct
2 Correct 549 ms 62552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 62552 KB Output is correct
2 Correct 667 ms 62552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 62552 KB Output is correct
2 Correct 600 ms 62552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 62552 KB Output is correct
2 Correct 439 ms 62552 KB Output is correct