Submission #210028

# Submission time Handle Problem Language Result Execution time Memory
210028 2020-03-16T11:31:41 Z ZwariowanyMarcin Drzava (COCI15_drzava) C++14
160 / 160
943 ms 5900 KB
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(), x.end()

using namespace std;

const int N = 50500;
const int K = 35;

int n, k;
int x[N], y[N], z[N];

int p[N];

int find(int x) {
	if (x == p[x]) return x;
	return p[x] = find(p[x]);
}

void unia(int x, int y) {
	p[find(x)] = find(y);
}

vector <int> points, v[N];
set <pair<int, int>> s; // {y, indeks}

LL dis(int a, int b) {
	return (LL) (x[a] - x[b]) * (x[a] - x[b]) + (LL) (y[a] - y[b]) * (y[a] - y[b]);
}

int dp[K][2];

bool ok(LD d) {
	rep(i, 1, n) {
		p[i] = i;
		v[i].clear();
	}
	s.clear();
	int j = 0;
	LD D = d * d;
	rep(i, 0, n - 1) {
		int ID = points[i];
		int X = x[ID];
		int Y = y[ID];
		while (X - x[points[j]] > d) {
			s.erase({y[points[j]], points[j]});
			j++;
		}
		int f = 0;
		auto it = s.lower_bound(mp(Y - floor(d), -1));
		while (it != s.end() && it->fi <= Y + d) {
			if (dis(ID, it->se) <= D) unia(ID, it->se);
			it++;
			f++;
			if (f >= 8 * k) return true;
		}
		s.insert({Y, ID});
	}
	rep(i, 1, n) v[find(i)].pb(i);
	rep(i, 1, n) {
		if (v[i].empty()) continue;
		rep(j, 0, k - 1) dp[j][0] = 0;
		for (auto it : v[i]) {
			rep(j, 0, k - 1) dp[j][1] = dp[j][0];
			dp[z[it]][1] = 1;
			rep(j, 0, k - 1) dp[(j + z[it]) % k][1] |= dp[j][0];
			rep(j, 0, k - 1) dp[j][0] = dp[j][1];
		}
		if (dp[0][0] == 1) return true;
	}
	return false;
}
	

int main() {
	scanf ("%d%d", &n, &k);
	rep(i, 1, n) {
		scanf ("%d%d%d", x + i, y + i, z + i);
		z[i] %= k;
		points.pb(i);
	}
	sort(points.begin(), points.end(), [](int a, int b) {
		return x[a] < x[b];
	});
	LD L = 0.0, R = 1e9 + 100;
	rep(i, 1, 50) {
		LD M = (L + R) / 2;
		if (ok(M)) R = M;
		else L = M;
	}
	printf("%.3Lf\n", L); 
		
	return 0;
}

Compilation message

drzava.cpp: In function 'int main()':
drzava.cpp:87:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &k);
  ~~~~~~^~~~~~~~~~~~~~~~
drzava.cpp:89:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d%d%d", x + i, y + i, z + i);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 6 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 6 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 22 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1532 KB Output is correct
2 Correct 14 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 22 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 26 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 22 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 15 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1528 KB Output is correct
2 Correct 160 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 932 ms 5608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 943 ms 5620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 685 ms 5368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 623 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 899 ms 5900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 550 ms 5236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 517 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 518 ms 4464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1528 KB Output is correct
2 Correct 597 ms 5292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 450 ms 5364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1528 KB Output is correct
2 Correct 502 ms 5200 KB Output is correct