제출 #1230793

#제출 시각아이디문제언어결과실행 시간메모리
1230793MatthewwwwDrzava (COCI15_drzava)C++17
160 / 160
653 ms12732 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#ifdef LOCAL
#define err cerr
#else
#define err if (0) cerr
#endif

const int num = 10;

struct Dsu {
	vector<int> par;
	vector<vector<int>> chd;
	Dsu (int N): par(N, -1), chd(N) {}
	int fpar (int x) { return par[x] < 0 ? x : par[x] = fpar(par[x]);}
	int merge (int x, int y) {
		if ((x = fpar(x)) == (y = fpar(y))) return -1;
		if (par[x] < par[y]) swap(x, y);
		par[y] += par[x];
		par[x] = y;
		chd[y].push_back(x);
		return y;
	}
	void get (int i, vector<int> &vt) {
		vt.push_back(i);
		for (int j: chd[i]) get(j, vt);
	}
};

ll d2 (pair<int, int> a, pair<int, int> b) { return (ll)(a.f-b.f)*(ll)(a.f-b.f)+(ll)(a.s-b.s)*(ll)(a.s-b.s);}
int isqrt (ll x) { return (int)sqrt(x);}

bool check (vector<int> vt, int k) {
	vector<bool> dp(k, 0);
	for (int i: vt) {
		vector<bool> pd = dp;
		dp[i%k] = true;
		for (int j = 0; j < k; j++) if (pd[j]) dp[(j+i)%k] = true;
	}
	return dp[0];
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, k;
	cin >> n >> k;
	vector<pair<pair<int, int>, int>> raw(n);
	vector<pair<int, int>> vt(n);
	vector<int> w(n);
	for (auto &i: raw) cin >> i.f.f >> i.f.s >> i.s;
	sort(raw.begin(), raw.end());
	for (int i = 0; i < n; i++) {
		vt[i] = raw[i].f;
		w[i] = raw[i].s;
	}
	vector<pair<ll, pair<int, int>>> edges;
	set<pair<int, int>> st; // y then index
	priority_queue<pair<int, int>> pq; // x then index
	ll len = 1e18;
	for (int i = 0; i < n; i++) {
		auto l = st.lower_bound({vt[i].s-isqrt(len), -1});
		auto r = st.upper_bound({vt[i].s+isqrt(len), n});
		vector<pair<ll, int>> dt;
		for (auto it = l; it != r; ++it) dt.push_back({d2(vt[i], vt[(*it).s]), (*it).s});
		sort(dt.begin(), dt.end());
		if (dt.size() >= num-1) {
			for (int j = 0; j < num-1; j++) edges.push_back({dt[j].f, {dt[j].s, i}});
			len = min(len, dt[num-2].f);
		} else {
			for (auto j: dt) edges.push_back({j.f, {j.s, i}});
		}
		while (pq.size() && pq.top().f < vt[i].f-isqrt(len)) {
			st.erase({vt[pq.top().s].s, pq.top().s});
			pq.pop();
		}
		pq.push({vt[i].f, i});
		st.insert({vt[i].s, i});
	}
	sort(edges.begin(), edges.end());
	Dsu dsu(n);
	for (auto i: edges) err << i.f << " " << i.s.f << " " << i.s.s << "\n";
	for (auto i: edges) {
		int rt = dsu.merge(i.s.f, i.s.s);
		if (!~rt) continue;
		vector<int> v;
		dsu.get(rt, v);
		vector<int> vn;
		for (int j: v) vn.push_back(w[j]);
		if (check(vn, k)) return cout << fixed << setprecision(3) << sqrt(i.f) << "\n", 0;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...