답안 #246603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246603 2020-07-09T17:29:57 Z xiryss Drzava (COCI15_drzava) C++17
64 / 160
1000 ms 20112 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 };
	}
};
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> 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)
	{
		vector<int> now;
		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) now.pbc(tree[v][j].second);
		return now;
	}
	auto now1 = get(2 * v + 1, l, (l + r) / 2, ql, qr, x, y);
	auto now2 = get(2 * v + 2, (l + r) / 2, r, ql, qr, x, y);
	for (int i : now2) now1.pbc(i);
	if (now1.size() >= 4 * k + 3)assert(0);
	return now1;
}
bool cmp(query a, query b)
{
	return a.r < b.r;
}
vector<int> ta;
vector<ld> xs;
	vector<ld> ys;
bool check(ld dst)
{
	fill(f, f + MAXN, 0);
	vector<query> handle;
	vector<int> answers(n);
	for (int i = 0; i < n; ++i)
	{
		int ans = 0;
		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;
		handle.pbc(query(xfs - 1, i, yfs, yss, 0));
		handle.pbc(query(xss, i, yfs, yss, 1));
		for (int j = 0; j < n; ++j)
		{
			if (a[j].first.first >= xm && a[j].first.first <= xmm && a[j].first.second >= ym && a[j].first.second <= ymm)
			{
				++ans;
			}
		}
		if (ans >= 8 * k + 3) return 1;
	}
	sort(all(handle), 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 < handle.size() && handle[lft].r < i) ++lft;
		while (lft < handle.size() && 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;
	flg = 0;
	for (int i = 1; i <= n; ++i) make(i);
	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;
		vector<int> joint = 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)
			{
				unite(i + 1, j + 1);
				if (flg) return 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 = 3e8;
	for (int cnt = 0; cnt < 60; ++cnt)
	{
		ld m = (l + r) / 2;
		if (check(m))r = m;
		else  l = m;
	}
	cout << fixed << setprecision(3) << r;
	sp;
}

Compilation message

drzava.cpp: In function 'std::vector<int> get(int, int, int, int, int, int, int)':
drzava.cpp:162: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) now.pbc(tree[v][j].second);
                    ~~^~~~~~~~~~~~~~~~
drzava.cpp:168:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (now1.size() >= 4 * k + 3)assert(0);
      ~~~~~~~~~~~~^~~~~~~~~~~~
drzava.cpp: In function 'bool check(ld)':
drzava.cpp:205:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0 ;i< ta.size();++i)
                  ~^~~~~~~~~~~
drzava.cpp:209:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (lft < handle.size() && handle[lft].r < i) ++lft;
          ~~~~^~~~~~~~~~~~~~~
drzava.cpp:210:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (lft < handle.size() && handle[lft].r == i)
          ~~~~^~~~~~~~~~~~~~~
drzava.cpp:247: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:299:2: note: in expansion of macro 'sp'
  sp;
  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Correct 11 ms 6528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Correct 12 ms 6400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6512 KB Output is correct
2 Correct 228 ms 6784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 6528 KB Output is correct
2 Correct 234 ms 6776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Correct 119 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Correct 207 ms 6888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6512 KB Output is correct
2 Correct 266 ms 6776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Correct 110 ms 6656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Execution timed out 1096 ms 13040 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6528 KB Output is correct
2 Execution timed out 1091 ms 19564 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 6400 KB Output is correct
2 Execution timed out 1096 ms 19308 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 6400 KB Output is correct
2 Execution timed out 1089 ms 19052 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Execution timed out 1093 ms 19952 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Execution timed out 1096 ms 19696 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6512 KB Output is correct
2 Execution timed out 1097 ms 19968 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Execution timed out 1094 ms 19856 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Execution timed out 1089 ms 19836 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Execution timed out 1092 ms 19864 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6400 KB Output is correct
2 Execution timed out 1097 ms 20080 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 6512 KB Output is correct
2 Execution timed out 1091 ms 20112 KB Time limit exceeded