답안 #98768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98768 2019-02-25T17:17:46 Z youngyojun Park (BOI16_park) C++11
100 / 100
352 ms 32464 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
using namespace std;
typedef long long ll;
typedef __int128_t lll;
typedef long double ld;
typedef pair<int, int> pii;
ll pw(ll n) { return n*n; }
lll pwlll(lll n) { return n*n; }
ll dst(const pii &a, const pii &b) { return pw(a.first-b.first) + pw(a.second-b.second); }
 
const int MAXN = 2055;
const int MAXK = 100055;
 
struct EVT {
	EVT(int a, int b, int c) : a(a), b(b), c(c) {}
	int a, b, c;
 
	bool operator < (const EVT &t) const { return c < t.c; }
};
 
vector<pii> KEYV[5][5];
 
vector<EVT> EV;
vector<int> CV, CO[MAXK];
 
int ud[MAXN];
 
int C[MAXK], D[MAXK], CI[MAXK];
pii A[MAXN]; int B[MAXN];
 
int Ans[MAXK];
 
int W, H, N, K;
 
int uf(int i) { return i == ud[i] ? i : (ud[i] = uf(ud[i])); }
void uf(int a, int b) { ud[uf(b)] = uf(a); }
 
int main() {
	ios::sync_with_stdio(false);
	iota(ud, ud+MAXN, 0);
 
	cin >> N >> K >> W >> H;
	for(int i = 1; i <= N; i++)
		cin >> A[i].first >> A[i].second >> B[i];
	for(int i = 1; i <= K; i++) {
		cin >> C[i] >> D[i];
		CV.eb(C[i]);
	}
	sorv(CV); univ(CV);
	for(int i = 1; i <= K; i++) {
		CI[i] = int(lower_bound(allv(CV), C[i]) - CV.begin());
		CO[CI[i]].eb(i);
	}
	
	for(int i = 1; i <= N; i++) for(int j = i+1; j <= N; j++) {
		ll l = dst(A[i], A[j]);
		int s = 0, e = sz(CV); for(int m; s < e;) {
			m = (s+e) >> 1;
			if(lll(l) < pwlll(ll(CV[m]) * 2 + B[i] + B[j])) e = m;
			else s = m+1;
		}
		EV.eb(i, j, s);
	}
	for(int i = 1; i <= N; i++) {
		int l = A[i].second - B[i];
		int s = 0, e = sz(CV); for(int m; s < e;) {
			m = (s+e) >> 1;
			if(l < CV[m]*2) e = m;
			else s = m+1;
		}
		EV.eb(i, N+1, s);
	}
	for(int i = 1; i <= N; i++) {
		int l = W - A[i].first - B[i];
		int s = 0, e = sz(CV); for(int m; s < e;) {
			m = (s+e) >> 1;
			if(l < CV[m]*2) e = m;
			else s = m+1;
		}
		EV.eb(i, N+2, s);
	}
	for(int i = 1; i <= N; i++) {
		int l = H - A[i].second - B[i];
		int s = 0, e = sz(CV); for(int m; s < e;) {
			m = (s+e) >> 1;
			if(l < CV[m]*2) e = m;
			else s = m+1;
		}
		EV.eb(i, N+3, s);
	}
	for(int i = 1; i <= N; i++) {
		int l = A[i].first - B[i];
		int s = 0, e = sz(CV); for(int m; s < e;) {
			m = (s+e) >> 1;
			if(l < CV[m]*2) e = m;
			else s = m+1;
		}
		EV.eb(i, N+4, s);
	}
	sorv(EV);
 
	{
		KEYV[1][2].eb(N+1, N+2); KEYV[1][2].eb(N+1, N+3); KEYV[1][2].eb(N+1, N+4);
		KEYV[2][3].eb(N+2, N+1); KEYV[2][3].eb(N+2, N+3); KEYV[2][3].eb(N+2, N+4);
		KEYV[3][4].eb(N+3, N+1); KEYV[3][4].eb(N+3, N+2); KEYV[3][4].eb(N+3, N+4);
		KEYV[1][4].eb(N+4, N+1); KEYV[1][4].eb(N+4, N+2); KEYV[1][4].eb(N+4, N+3);
 
		KEYV[1][3].eb(N+1, N+3); KEYV[1][3].eb(N+1, N+4); KEYV[1][3].eb(N+2, N+3); KEYV[1][3].eb(N+2, N+4);
		KEYV[2][4].eb(N+1, N+2); KEYV[2][4].eb(N+1, N+3); KEYV[2][4].eb(N+4, N+2); KEYV[2][4].eb(N+4, N+3);
	}
	for(int co = 0, evi = 0; co < K; co++) {
		for(; evi < sz(EV) && EV[evi].c == co; evi++) {
			uf(EV[evi].a, EV[evi].b);
		}
 
		for(int v : CO[co]) {
			int t = D[v];
			Ans[v] |= 1<<t;
			for(int a = 1; a <= 4; a++) for(int b = a+1; b <= 4; b++) {
				if(a != t && b != t) continue;
				bool flag = false;
				for(auto &p : KEYV[a][b]) {
					if(uf(p.first) == uf(p.second)) {
						flag = true;
						break;
					}
				}
				if(!flag) Ans[v] |= 1<<a | 1<<b;
			}
		}
	}
 
	for(int i = 1; i <= K; i++) {
		for(int j = 1; j <= 4; j++)
			if(Ans[i] & (1<<j)) printf("%d", j);
		puts("");
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 27604 KB Output is correct
2 Correct 114 ms 27772 KB Output is correct
3 Correct 123 ms 27548 KB Output is correct
4 Correct 112 ms 27604 KB Output is correct
5 Correct 114 ms 27592 KB Output is correct
6 Correct 136 ms 27592 KB Output is correct
7 Correct 133 ms 27604 KB Output is correct
8 Correct 118 ms 27492 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 8128 KB Output is correct
2 Correct 125 ms 8312 KB Output is correct
3 Correct 105 ms 7876 KB Output is correct
4 Correct 97 ms 8436 KB Output is correct
5 Correct 117 ms 8464 KB Output is correct
6 Correct 104 ms 8564 KB Output is correct
7 Correct 89 ms 8072 KB Output is correct
8 Correct 106 ms 8168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 114 ms 27604 KB Output is correct
2 Correct 114 ms 27772 KB Output is correct
3 Correct 123 ms 27548 KB Output is correct
4 Correct 112 ms 27604 KB Output is correct
5 Correct 114 ms 27592 KB Output is correct
6 Correct 136 ms 27592 KB Output is correct
7 Correct 133 ms 27604 KB Output is correct
8 Correct 118 ms 27492 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 131 ms 8128 KB Output is correct
12 Correct 125 ms 8312 KB Output is correct
13 Correct 105 ms 7876 KB Output is correct
14 Correct 97 ms 8436 KB Output is correct
15 Correct 117 ms 8464 KB Output is correct
16 Correct 104 ms 8564 KB Output is correct
17 Correct 89 ms 8072 KB Output is correct
18 Correct 106 ms 8168 KB Output is correct
19 Correct 282 ms 31564 KB Output is correct
20 Correct 320 ms 31912 KB Output is correct
21 Correct 320 ms 31820 KB Output is correct
22 Correct 304 ms 32076 KB Output is correct
23 Correct 343 ms 32464 KB Output is correct
24 Correct 352 ms 32336 KB Output is correct