Submission #47814

# Submission time Handle Problem Language Result Execution time Memory
47814 2018-05-07T16:13:37 Z tieunhi Drzava (COCI15_drzava) C++14
8 / 160
20 ms 3188 KB
#include <bits/stdc++.h>
#define PB push_back
#define N 50005
using namespace std;
using db = double;

int n, k, dp[N][31], curTime, dd[N];

vector<int> g[N], component;

struct Point
{
	int x, y, sz;
	Point(int _x=0, int _y=0, int _sz=0) : x(_x), y(_y), sz(_sz) {}
	friend bool operator < (const Point& a, const Point& b)
	{
        return a.x < b.x;
    }
	Point operator + (Point P) const
	{
		return {x + P.x, y + P.y, sz + P.sz};
	}
	Point operator - (Point P) const
	{
		return {x - P.x, y - P.y, sz - P.sz};
	}
	long long operator % (Point P) const
	{
		return 1ll*x*P.x + 1ll*y*P.y;
	}
}a[N];

db dist(Point u, Point v)
{
	u = u - v;
	return 1.*sqrt(u%u);
}
struct cmp
{
	bool operator () (const int &p, const int &q)
	{
		if (a[p].y != a[q].y) return a[p].y < a[q].y;
		return p < q;
	}
};
set<int, cmp> s;


void DFS(int u)
{
	dd[u] = curTime;
	component.PB(u);
	for (auto v : g[u])
	{
		if (dd[v] == curTime) continue;
		DFS(v);
	}
}
bool exist()
{
	int m = component.size();
	if (m > k) return 1;
	for (int i = 0; i <= m; i++)
		for (int j = 0; j < k; j++) dp[i][j] = 0;
	dp[0][0] = 1;
	for (int i = 0; i < m; i++)
		for (int j = 0; j < k; j++)
			dp[i+1][(a[component[i]].sz + j) % k] |= dp[i][j];
	for (int i = 0; i < m; i++)
		for (int j = 0; j < k; j++)
			if ((j + a[component[i]].sz) % k == 0 && dp[i][j])
				return 1;
	return 0;
}
bool check(long long D)
{
	db d = sqrt(1.*D);
	for (int i = 1; i <= n; i++)
		g[i].clear();
	s.clear();

	int cur = 1;
	for (int i = 1; i <= n; i++)
	{
		while (cur < i && a[i].x - a[cur].x > d)
			s.erase(cur++);
		if (s.empty())
        {
            s.insert(i);
            continue;
        }
		a[0] = Point(a[i].x, a[i].y - d, 0);
		int cnt = 0;
		for (auto it = s.lower_bound(0); it != s.end(); it++)
		{
			int idx = *it;
			if (a[idx].y - a[i].y > d) break;
			if (++cnt >= 8*k)
				return 1;
			if (dist(a[idx], a[i]) <= d)
			{
				g[i].PB(idx);
				g[idx].PB(i);
			}
		}
		s.insert(i);
	}
	curTime++;
	for (int i = 1; i <= n; i++)
		if (dd[i] != curTime)
		{
			component.clear();
			DFS(i);
			if (exist())
				return 1;
		}
	return 0;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("INP.TXT", "r", stdin);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i].x >> a[i].y >> a[i].sz;
	sort(a+1, a+n+1);
	long long l = 0, r = 1e18;
	while (r - l > 1)
	{
		long long mid = (r + l)/2;
		if (check(mid)) r = mid;
		else l = mid;
	}
	cout <<fixed<<setprecision(3)<<sqrt(1.*r);
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2280 KB Output is correct
2 Correct 20 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3188 KB Output isn't correct
2 Halted 0 ms 0 KB -