답안 #252761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252761 2020-07-26T08:35:42 Z islingr Drzava (COCI15_drzava) C++14
64 / 160
569 ms 65540 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(e, x) for (auto &e : x)
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define f first
#define s second

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int N = 1 << 16, K = 1 << 6;
const ll inf = 2e8;
using point = complex<ll>;

point p[N];
short v[N], k;

int n, cur;
vector<int> cmp[N];
bool dp[K][K], vis[N];
vector<int> g[N];

void unite(int u, int v) { g[u].eb(v); g[v].eb(u); }
void dfs(int u) {
	cmp[cur].eb(u);
	vis[u] = true;
	trav(v, g[u]) if (!vis[v]) dfs(v);
}

bool f(ll d) {
	ld r = sqrt(ld(d));
	set<pair<ll, int>> S;

	int l = 0;
	rep(u, 0, n) g[u].clear(), vis[u] = false, cmp[u].clear();
	rep(i, 0, n) {
		if (real(p[i]) - real(p[l]) > r)
			S.erase({imag(p[l]), l}), ++l;
		for (auto it = S.lb({ceil(imag(p[i]) - r), -1});
			it != end(S) && it->f - r <= imag(p[i]); ++it)
			if (norm(p[it->s] - p[i]) <= d)
				unite(it->s, i);
		S.insert({imag(p[i]), i});
	}

	cur = 0;
	rep(u, 0, n) if (!vis[u]) dfs(u), ++cur;
	rep(z, 0, cur) {
		auto &a = cmp[z]; int n = sz(a);
		if (n > k) return true;
		rep(i, 0, n) rep(w, 0, k) dp[i][w] = 0;
		dp[0][v[a[0]]] = 1;
		rep(i, 1, n) {
			dp[i][v[a[i]]] = 1;
			rep(w, 0, k)
				if (dp[i - 1][w])
					dp[i][(w + v[a[i]]) % k] = dp[i][w] = true;
			if (dp[i][0]) return true;
		}
	}
	return false;
}

pair<point, short> tmp[N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> k;
	rep(i, 0, n) {
		int x, y, c; cin >> x >> y >> c;
		tmp[i] = {{x, y}, c % k};
	}
	sort(tmp, tmp + n, [&](auto a, auto b) {
		if (real(a.f) == real(b.f)) return imag(a.f) < imag(b.f);
		return real(a.f) < real(b.f);
	});
	rep(i, 0, n) tie(p[i], v[i]) = tmp[i];
	
	ll l = 0, r = inf * inf;
	while (r - l > 1) {
		ll m = l + (r - l + 1) / 2;
		if (f(m)) r = m;
		else l = m; 
	}
	cout << fixed << setprecision(3) << sqrt(ld(r));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 449 ms 7168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 352 ms 7180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 176 ms 5888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 427 ms 7160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 569 ms 7704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 98 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 351 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 347 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 354 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3328 KB Output is correct
2 Runtime error 345 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 345 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 337 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 347 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3328 KB Output is correct
2 Runtime error 336 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 348 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 349 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 345 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 343 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)