답안 #246638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246638 2020-07-09T20:28:39 Z xiryss Drzava (COCI15_drzava) C++17
64 / 160
1000 ms 23152 KB
//#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
/*#pragma GCC optimize("section-anchors")
#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
#pragma GCC optimize("vpt")
#pragma GCC optimize("rename-registers")
#pragma GCC optimize("move-loop-invariants")
#pragma GCC optimize("unswitch-loops")
#pragma GCC optimize("function-sections")
#pragma GCC optimize("data-sections")
#pragma GCC optimize("branch-target-load-optimize")
#pragma GCC optimize("branch-target-load-optimize2")
#pragma GCC optimize("btr-bb-exclusive")*/
//#pragma comment(linker, "/STACK:367077216")
#define _CRT_SECURE_NO_WARNINGS
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <string>
#include <cstdint>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define sqr(a) ((a) * (a))
#define sqrl(a) (ll(a)*ll(a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pin(p) cin >> p.first >> p.second;
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define rev(v) reverse(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define dab(v) for(auto i:v)cout<<i<<' ';
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
mt19937 rnd(time(0) + 228 + 'k' + 'e' + 'k' + 'e' + 'r' + 'o' + 'f' + 'e' + 'y');
const ld EPS = 1e-5;//(cos,-sin), (sin, cos)
bool checkprime(int x)
{
	for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0;
	return 1;
}
const ld PI = acos(-1);
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
const ll INF = 1e18;
int mod = MOD7;
const int inf = 1e9;
const int MAXN = 5e4 + 2;
int p[MAXN];
int sz[MAXN];
vector<int> have[MAXN];
pair<pair<int, int>, int> a[MAXN];

void make(int v)
{
	p[v] = v, sz[v] = 1;
	have[v] = { a[v - 1].second };
}
int fin(int v)
{
	return (v == p[v] ? v : p[v] = fin(p[v]));
}
bool flg = 0;
int n, k;

void unite(int a, int b)
{
	a = fin(a);
	b = fin(b);
	if (a == b) return;
	if (sz[a] < sz[b]) swap(a, b);
	for (int j : have[b]) have[a].pbc(j);
	p[b] = a;
	sz[a] += sz[b];
	if (sz[a] >= k) flg = 1;
}
int f[MAXN];
void add(int i, int x)
{
	for (; i < MAXN; i |= (i + 1)) f[i] += x;
}
int get(int r)
{
	int ans = 0;
	for (; r >= 0; r = (r & (r + 1)) - 1) ans += f[r];
	return ans;
}

int get(int l, int r)
{
	return get(r) - get(l - 1);
}
ld dist(pair<int, int> a, pair<int, int> b)
{
	return sqrt(sqrl(a.first - b.first) + sqrl(a.second - b.second));
}
struct query
{
	int r, i, x, y;
	bool type;
	query(int a, int b, int c, int d, bool e)
	{
		tie(r, i, x, y, type) = { a,b,c,d,e };
	}
	query()
	{
		r = i = x = y = type = 0;
	}
};
vector<pair<int,int>> tree[4 * MAXN];
void build(int v, int l, int r, vector<pair<int, int>>& kek)
{
	if (l == r - 1)
	{
		tree[v] = { kek[l] };
		return;
	}
	build(2 * v + 1, l, (l + r) / 2, kek);
	build(2 * v + 2, (l + r) / 2, r, kek);
	tree[v].clear();
	merge(all(tree[2 * v + 1]), all(tree[2 * v + 2]), back_inserter(tree[v]));
}
vector<int> joint;
void get(int v, int l, int r, int ql, int qr, int x, int y)
{
	if (l >= qr || ql >= r) return;
	if (l >= ql && r <= qr)
	{
		int xa = lower_bound(all(tree[v]), mp( x, -inf )) - tree[v].begin();
		for (int j = xa; j < tree[v].size() && tree[v][j].first <= y; ++j) joint.pbc(tree[v][j].second);
		return;
	}
	get(2 * v + 1, l, (l + r) / 2, ql, qr, x, y);
	get(2 * v + 2, (l + r) / 2, r, ql, qr, x, y);
}
bool cmp(query a, query b)
{
	return a.r < b.r;
}
vector<int> ta;
vector<ld> xs;
vector<ld> ys;
int answers[MAXN];
query handle[MAXN * 2];
int hsz = 0;
vector<int> available[MAXN];
bool check(ld dst)
{
	hsz = 0;
//	if (n >= 1e4 && cnt >= 20) assert(0);
	fill(f, f + MAXN, 0);
	fill(answers, answers + MAXN, 0);
	for (int i = 0; i < n; ++i)
	{
		ld xm = a[i].first.first - dst, xmm = a[i].first.first + dst;
		ld ym = a[i].first.second - dst, ymm = a[i].first.second + dst;
		int xfs = lower_bound(all(xs), xm) - xs.begin();
		int xss = upper_bound(all(xs), xmm) - xs.begin() - 1;
		int yfs = lower_bound(all(ys), ym) - ys.begin();
		int yss = upper_bound(all(ys), ymm) - ys.begin() - 1;	
		handle[hsz++] = query(xfs - 1, i, yfs, yss, 0);
		handle[hsz++] = query(xss, i, yfs, yss, 1);
	}
	sort(handle, handle + hsz, cmp);
	int lft = 0;
	for (int i = 0 ;i< ta.size();++i)
	{
		int nowy = lower_bound(all(ys), (ld)a[ta[i]].first.second) - ys.begin();
		add(nowy, 1);
		while (lft < hsz && handle[lft].r < i) ++lft;
		while (lft < hsz && handle[lft].r == i)
		{
			int now = get(handle[lft].x, handle[lft].y);
			if (handle[lft].type == 0) answers[handle[lft].i] -= now;
			else answers[handle[lft].i] += now;
			++lft;
		}
	}
	for (int i = 0; i < n; ++i) if (answers[i] >= 8 * k + 3)  return 1;
	return 0;
}
bool check2(ld dst)
{
	flg = 0;
	for (int i = 1; i <= n; ++i) make(i);
	for (int i = 0; i < n; ++i)
	{
		for (int j : available[i])
		{
			if (dist(a[i].first, a[j].first) <= dst)
			{
				unite(i + 1, j + 1);
			}
		}
	}
	vector<bool> used(n + 1);
	for (int i = 0; i < n; ++i)
	{
		if (used[fin(i + 1)]) continue;
		used[fin(i + 1)] = 1;
		vector<int> means = have[fin(i + 1)];
		vector<vector<bool>> dp(means.size() + 1, vector<bool>(k + 1));
		dp[0][0] = 1;
		for (int j = 0; j < means.size(); ++j)
		{
			for (int w = 0; w <= k; ++w)
			{
				if (!dp[j][w]) continue;
				dp[j + 1][w] = 1;
				int tw = w + means[j];
				if (tw == k) return 1;
				tw %= k;
				dp[j + 1][tw] = 1;
			}
		}
	}
	return 0;
}
signed main()
{
	fastio();
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first.first >> a[i].first.second >> a[i].second;
		a[i].second %= k;
	}
	ta.resize(n);
	iota(all(ta), 0);
	sort(all(ta), [&](int x, int y) {return a[x].first.first < a[y].first.first; });

	for (int i : ta) xs.pbc(a[i].first.first);
	for (int i : ta) ys.pbc(a[i].first.second);
	sort(all(ys));
	vector<pair<int, int>> now;
	for (int i : ta)
	{
		int nowy = lower_bound(all(ys), (ld)a[i].first.second) - ys.begin();

		now.pbc({ nowy, i });
	}
	build(0, 0, n, now);
	/*
	for (int i = 0; i < n; ++i)
	{
		cout << a[i].second << endl;
	}*/
	ld l = 0, r = 1.5e8;
	for (int cnt = 0; cnt < 47; ++cnt)
	{
		ld m = (l + r) / 2;
		if (check(m))r = m;
		else  l = m;
	}
	ld dst = r;
	for (int i = 0; i < n; ++i)
	{
		ld xm = a[i].first.first - dst, xmm = a[i].first.first + dst;
		ld ym = a[i].first.second - dst, ymm = a[i].first.second + dst;
		int xfs = lower_bound(all(xs), ld(xm)) - xs.begin();
		int xss = upper_bound(all(xs), xmm) - xs.begin() - 1;
		int yfs = lower_bound(all(ys), ld(ym)) - ys.begin();
		int yss = upper_bound(all(ys), ymm) - ys.begin() - 1;
		joint.clear();
		get(0, 0, n, xfs, xss + 1, yfs, yss);
		for (int j : joint)
		{
			if (a[j].first.first >= xm && a[j].first.first <= xmm && a[j].first.second >= ym && a[j].first.second <= ymm && dist(a[i].first, a[j].first) <= dst)
			{
				available[i].pbc(j);
			}
		}
	}
	l = 0;
	for (int cnt = 0; cnt < 47; ++cnt)
	{
		ld m = (l + r) / 2;
		if (check2(m)) r = m;
		else l = m;
	}
	cout << fixed << setprecision(3) << r;
	sp;
}

Compilation message

drzava.cpp: In function 'void get(int, int, int, int, int, int, int)':
drzava.cpp:166:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = xa; j < tree[v].size() && tree[v][j].first <= y; ++j) joint.pbc(tree[v][j].second);
                    ~~^~~~~~~~~~~~~~~~
drzava.cpp: In function 'bool check(ld)':
drzava.cpp:202:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0 ;i< ta.size();++i)
                  ~^~~~~~~~~~~
drzava.cpp: In function 'bool check2(ld)':
drzava.cpp:240:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < means.size(); ++j)
                   ~~^~~~~~~~~~~~~~
drzava.cpp: In function 'int main()':
drzava.cpp:63:18: warning: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result [-Wunused-result]
 #define sp system("pause")
            ~~~~~~^~~~~~~~~
drzava.cpp:318:2: note: in expansion of macro 'sp'
  sp;
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 14 ms 9728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 9816 KB Output is correct
2 Correct 13 ms 9856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 61 ms 10488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Correct 53 ms 10280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 46 ms 10368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9840 KB Output is correct
2 Correct 69 ms 10636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9856 KB Output is correct
2 Correct 69 ms 10488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Correct 43 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9856 KB Output is correct
2 Execution timed out 1096 ms 15728 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1096 ms 22896 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1096 ms 22760 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1094 ms 22384 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1094 ms 23016 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1084 ms 23152 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1096 ms 23024 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9856 KB Output is correct
2 Execution timed out 1089 ms 23024 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1096 ms 23020 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1092 ms 23024 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1095 ms 23024 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 9728 KB Output is correct
2 Execution timed out 1091 ms 23020 KB Time limit exceeded