Submission #231052

# Submission time Handle Problem Language Result Execution time Memory
231052 2020-05-12T12:49:45 Z islingr Park (BOI16_park) C++14
100 / 100
383 ms 29868 KB
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;

using pii = pair<int, int>;
 
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define trav(x, v) for (auto &x : v)
#define eb(x...) emplace_back(x)
#define f first
#define s second

struct event {
	int r, c, i;
	bool operator<(const event &e) { return r < e.r; } 
};
int abs(const complex<int> &p) { return floor(hypot(real(p), imag(p))); }

constexpr int N = 1 << 11, M = 1 << 17;
int nxt[N], rnk[N], r[N], n, m, w, h;
complex<int> p[N];
event v[M];
string ans[M];
vector<pair<int, pii>> q;
vector<pii> c[4][4] = {
		{{}, {{1, 3}, {1, 0}, {1, 2}}, {{1, 0}, {1, 3}, {2, 0}, {2, 3}}, {{0, 1}, {0, 2}, {0, 3}}},
		{{{1, 3}, {1, 0}, {1, 2}}, {}, {{2, 1}, {2, 0}, {2, 3}}, {{1, 2}, {1, 3}, {0, 2}, {0, 3}}},
		{{{2, 3}, {0, 1}, {1, 3}, {0, 2}}, {{0, 2}, {1, 2}, {2, 3}}, {}, {{1, 3}, {2, 3}, {0, 3}}},
		{{{0, 3}, {0, 2}, {0, 1}}, {{3, 0}, {3, 1}, {2, 0}, {2, 1}}, {{1, 3}, {0, 3}, {2, 3}}, {}}
	};

int head(int u) { return nxt[u] != -1 ? nxt[u] = head(nxt[u]) : u; }
void unite(int u, int v) {
	u = head(u); v = head(v);
	if (u == v) return;
	if (rnk[u] < rnk[v]) nxt[u] = v;
	else {
		nxt[v] = u;
		if (rnk[u] == rnk[v]) ++rnk[u];
	}
}
bool same(int u, int v) { return head(u) == head(v); }
void unite(pii p) { unite(p.f, p.s); }

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
 
	cin >> n >> m >> w >> h;
	rep(i, 0, n) {
		int x, y; cin >> x >> y >> r[i];
		p[i] = {x, y};
	}

	rep(i, 0, n) {
		int x = real(p[i]), y = imag(p[i]), j = i + 4;
		q.eb(x - r[i], pii(j, 0));
		q.eb(y - r[i], pii(j, 1));
		q.eb(w - x - r[i], pii(j, 2));
		q.eb(h - y - r[i], pii(j, 3));
	}
	rep(i, 0, n) rep(j, i + 1, n) q.eb(abs(p[i] - p[j]) - r[i] - r[j], pii(i + 4, j + 4));
	sort(q.rbegin(), q.rend());

	rep(i, 0, m) {
		cin >> v[i].r >> v[i].c; --v[i].c;
		v[i].i = i;
	}
	sort(v, v + m);
	rep(u, 0, n + 4) nxt[u] = -1;
	rep(i, 0, m) {
		while (!q.empty() && q.back().f < 2 * v[i].r) {
			unite(q.back().s); q.pop_back();
		}
		rep(j, 0, 4) {
			bool works = true;
			trav(x, c[v[i].c][j])
				if (same(x.f, x.s))
					works = false;
			if (works) ans[v[i].i] += '1' + j;
		}
	}

	rep(i, 0, m) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 328 ms 29256 KB Output is correct
2 Correct 333 ms 29256 KB Output is correct
3 Correct 331 ms 29304 KB Output is correct
4 Correct 325 ms 29260 KB Output is correct
5 Correct 328 ms 29268 KB Output is correct
6 Correct 331 ms 29252 KB Output is correct
7 Correct 276 ms 29280 KB Output is correct
8 Correct 267 ms 29288 KB Output is correct
9 Correct 7 ms 4480 KB Output is correct
10 Correct 6 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6388 KB Output is correct
2 Correct 60 ms 6392 KB Output is correct
3 Correct 59 ms 6388 KB Output is correct
4 Correct 59 ms 6388 KB Output is correct
5 Correct 59 ms 6388 KB Output is correct
6 Correct 57 ms 6388 KB Output is correct
7 Correct 56 ms 6008 KB Output is correct
8 Correct 54 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 29256 KB Output is correct
2 Correct 333 ms 29256 KB Output is correct
3 Correct 331 ms 29304 KB Output is correct
4 Correct 325 ms 29260 KB Output is correct
5 Correct 328 ms 29268 KB Output is correct
6 Correct 331 ms 29252 KB Output is correct
7 Correct 276 ms 29280 KB Output is correct
8 Correct 267 ms 29288 KB Output is correct
9 Correct 7 ms 4480 KB Output is correct
10 Correct 6 ms 4480 KB Output is correct
11 Correct 56 ms 6388 KB Output is correct
12 Correct 60 ms 6392 KB Output is correct
13 Correct 59 ms 6388 KB Output is correct
14 Correct 59 ms 6388 KB Output is correct
15 Correct 59 ms 6388 KB Output is correct
16 Correct 57 ms 6388 KB Output is correct
17 Correct 56 ms 6008 KB Output is correct
18 Correct 54 ms 5880 KB Output is correct
19 Correct 382 ms 29740 KB Output is correct
20 Correct 376 ms 29868 KB Output is correct
21 Correct 383 ms 29868 KB Output is correct
22 Correct 361 ms 29724 KB Output is correct
23 Correct 379 ms 29740 KB Output is correct
24 Correct 318 ms 29744 KB Output is correct