Submission #252763

# Submission time Handle Problem Language Result Execution time Memory
252763 2020-07-26T08:42:54 Z islingr Drzava (COCI15_drzava) C++14
64 / 160
573 ms 65544 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;

short k;

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

using pii = pair<int, int>;

pair<pii, short> tmp[N];
pii p(int i) { return tmp[i].f; }
short v(int i) { return tmp[i].s; }

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);
}

ll norm(const pii &p, const pii &q) {
	return 1ll * (p.f - q.f) * (p.f - q.f) + 1ll * (p.s - q.s) * (p.s - q.s);
}

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

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

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);
	
	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));
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 437 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 371 ms 7132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 172 ms 5888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Correct 416 ms 7092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 573 ms 7656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 102 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 353 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory 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)
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3456 KB Output is correct
2 Runtime error 369 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3328 KB Output is correct
2 Runtime error 354 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 355 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 364 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 361 ms 65544 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 355 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 358 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3328 KB Output is correct
2 Runtime error 348 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3456 KB Output is correct
2 Runtime error 357 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Runtime error 352 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)