답안 #349381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349381 2021-01-17T13:23:55 Z sinamhdv Park (BOI16_park) C++11
0 / 100
2500 ms 496 KB
#include <bits/stdc++.h>
using namespace std;

#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define msub(a, b) ((mod + ((ll)(a) - (b)) % mod) % mod)
#define mdiv(a, b) ((ll)(a) * poww((b), mod - 2) % mod)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'

#define MAXN 2020

int n, m;
int w, h;
int tx[MAXN], ty[MAXN], tr[MAXN];
int ans[5][5];
int cn;
int comp[MAXN];

int crad;

bool olap(int a, int b)
{
	if (a > n && b > n)
		return false;
	if (a > b)
		swap(a, b);
	if (b > n)	// C - L
	{
		b -= n;
		ll d;
		if (b == 1)
			d = (ll)ty[a] - crad;
		else if (b== 2)
			d = (ll)w - tx[a] - crad;
		else if (b == 3)
			d = (ll)h - ty[a] - crad;
		else if (b == 4)
			d = (ll)tx[a] - crad;

		return ((ll)tr[a] + crad > d);
	}
	else	// C - C
	{
		ll dx = abs(tx[a] - tx[b]);
		ll dy = abs(ty[a] - ty[b]);
		ll dr = (ll)tr[a] + tr[b] + (ll)2 * crad;
		return (dr * dr > dx*dx + dy*dy);
	}
}

void dfs(int v)
{
	comp[v] = cn;
	FOR(i, 1, n + 5)
	{
		if (comp[i] || !olap(v, i))
			continue;
		dfs(i);
	}
}

bool check(int r, int src, int dst)
{
	memset(comp, 0, sizeof(comp));
	cn = 0;

	crad = r;

	FOR(i, 1, n + 5)
	{
		if (!comp[i])
		{
			cn++;
			dfs(i);
		}
	}

	//dbgr(comp + 1, comp + n + 5);

	if (abs(src - dst) == 2)
	{
		int x1 = src + n;
		int x2 = (src % 4) + 1 + n;
		int y1 = dst + n;
		int y2 = (dst % 4) + 1 + n;

		return (comp[x1] != comp[y2] && comp[x1] != comp[y1] && comp[x2] != comp[y1] && comp[x2] != comp[y2]);
	}
	else
	{
		if (src == 1 && dst == 4)
			swap(src, dst);

		bool res = true;
		FOR(i, 1, 5)
			if (i != src)
				res &= (comp[src + n] != comp[i + n]);
		return res;
	}
}

int32_t main(void)
{
	fast_io;
	cin >> n >> m;
	cin >> w >> h;
	FOR(i, 1, n + 1)
	{
		cin >> tx[i] >> ty[i] >> tr[i];
	}


	while (m--)
	{
		int r, e;
		cin >> r >> e;
		string res;
		FOR(i, 1, 5)
		{
			if (e == i || check(r, e, i))
				res += (i + '0');
		}
		cout << res << endl;
	}
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 364 KB Output is correct
2 Incorrect 63 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2562 ms 496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 364 KB Output is correct
2 Incorrect 63 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -