Submission #246609

# Submission time Handle Problem Language Result Execution time Memory
246609 2020-07-09T17:36:46 Z xiryss Drzava (COCI15_drzava) C++17
0 / 160
901 ms 49212 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() >=  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)
	{
		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.pbc(query(xfs - 1, i, yfs, yss, 0));
		handle.pbc(query(xss, i, yfs, yss, 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 = 1.5e8;
	for (int cnt = 0; cnt < 40; ++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() >=  k + 3)assert(0);
      ~~~~~~~~~~~~^~~~~~~~~
drzava.cpp: In function 'bool check(ld)':
drzava.cpp:196:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0 ;i< ta.size();++i)
                  ~^~~~~~~~~~~
drzava.cpp:200:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (lft < handle.size() && handle[lft].r < i) ++lft;
          ~~~~^~~~~~~~~~~~~~~
drzava.cpp:201:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (lft < handle.size() && handle[lft].r == i)
          ~~~~^~~~~~~~~~~~~~~
drzava.cpp:238: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:290:2: note: in expansion of macro 'sp'
  sp;
  ^~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 16 ms 12800 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 6400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 24 ms 13304 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Runtime error 25 ms 13312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6400 KB Output is correct
2 Runtime error 20 ms 13312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 23 ms 13312 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6512 KB Output is correct
2 Runtime error 25 ms 13440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6512 KB Output is correct
2 Runtime error 18 ms 13184 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6400 KB Output is correct
2 Runtime error 353 ms 29212 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6400 KB Output is correct
2 Runtime error 722 ms 48500 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6400 KB Output is correct
2 Runtime error 705 ms 48092 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 12 ms 6528 KB Output is correct
2 Runtime error 691 ms 47556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 761 ms 49108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6528 KB Output is correct
2 Runtime error 826 ms 49120 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 880 ms 49172 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 870 ms 49056 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6528 KB Output is correct
2 Runtime error 892 ms 49148 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 901 ms 49068 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6512 KB Output is correct
2 Runtime error 890 ms 49212 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6400 KB Output is correct
2 Runtime error 859 ms 49084 KB Execution killed with signal 11 (could be triggered by violating memory limits)