답안 #638066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638066 2022-09-04T14:21:20 Z Karliver Park (BOI16_park) C++17
100 / 100
304 ms 37636 KB
	
#include <bits/stdc++.h>

#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()
#define ff first
#define se second
#define mp make_pair
using ll = long long;
int MOD = 998244353;
const int INF = 1e9 + 1;
const int N = 2e5 + 10;

const double eps = 1e-7;

template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
    return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
    return (x > y ? x = y, 1 : 0);
}



void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
int n, m, w, h;

double dist(int x1, int y1, int x2, int y2) {
	long long dx = x1-x2, dy = y1-y2;
	return double(sqrt(dx * dx + dy * dy));
}
struct DSU {

	vector<int> e;

	DSU(int N) { e = vector<int>(N, -1); }


	// get representive component (uses path compression)

	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }


	bool same_set(int a, int b) { return get(a) == get(b); }


	int size(int x) { return -e[get(x)]; }


	bool unite(int x, int y) {  // union by size

		x = get(x), y = get(y);

		if (x == y) return false;

		if (e[x] > e[y]) swap(x, y);

		e[x] += e[y]; e[y] = x; return true;

	}

};
void solve() {
	
	
	cin >> n >> m >> w >> h;
	
	vector<int> x(n), y(n);
	V<double> r(n);
	
	forn(i, n) cin >> y[i] >> x[i] >> r[i];
	
	vector<array<int, 3>> Q(m);
	forn(i, m) {
		cin >> Q[i][0] >> Q[i][1];
		Q[i][1]--;
		Q[i][2] = i;
	}
	vector<pair<double, pair<int, int>>> E;
	for(int i = 0;i < n;++i) {
		for(int j = i + 1;j < n;++j) {
			E.push_back({dist(x[i], y[i], x[j], y[j])-r[i]-r[j], {i, j}});
		}
		E.push_back({y[i]-r[i], {i, n}});
		E.push_back({x[i]-r[i], {i, n+1}});
		E.push_back({w-y[i]-r[i], {i, n+2}});
		E.push_back({h-x[i]-r[i], {i, n+3}});
	}
	
	DSU D(n + 5);
	V<string> ret(m);
	sort(begin(Q), end(Q), [&](array<int, 3> one, array<int, 3> two) {
		return one[0] < two[0];
	});
	sort(begin(E), end(E), [&](pair<double, pair<int, int>> one, pair<double, pair<int, int>> two) {
		return one.ff < two.ff;
	});
	//debug(E);
	int k = 0;
	auto can = [&](int f, int  g) {
		if(f == g) return true;
		if(f > g) swap(f, g);
		if(D.same_set(n+f, n+(f+1)%4))return false;
		if(D.same_set(n+g, n+(g+1)%4))return false;
		
		if(f == 0 && g == 3)
			return !D.same_set(n, n+2);
		else if(f+1==g) {
			return !D.same_set(n+(f+1)%4, n+(f+3)%4);
		}
		else {
			if(D.same_set(n+f, n+(f+2)%4))return false;
			if(D.same_set(n+(f+1)%4, n+(f+3)%4))return false;
			return true;
		}
	};
	
	for(auto [R, cor, i] : Q) {
		while(k < sz(E) && E[k].ff < R * 2.0) {
			D.unite(E[k].se.ff, E[k].se.se);
			++k;
		}
		string res = "";
		forn(j, 4) if(can(cor, j)) res += '0' + j + 1;
		
		ret[i] = res;
	}
	forn(i, m) cout << ret[i] << '\n';
	
}
void test_case() {
    int t;
    cin >> t;
    forn(p, t) {

        //cout << "Case #" << p + 1 << ": ";
        solve();
    }
}
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 33320 KB Output is correct
2 Correct 258 ms 33372 KB Output is correct
3 Correct 262 ms 33348 KB Output is correct
4 Correct 256 ms 33324 KB Output is correct
5 Correct 261 ms 33328 KB Output is correct
6 Correct 260 ms 33388 KB Output is correct
7 Correct 238 ms 33308 KB Output is correct
8 Correct 230 ms 33280 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 6476 KB Output is correct
2 Correct 49 ms 6464 KB Output is correct
3 Correct 37 ms 6320 KB Output is correct
4 Correct 38 ms 6476 KB Output is correct
5 Correct 39 ms 6412 KB Output is correct
6 Correct 43 ms 6416 KB Output is correct
7 Correct 37 ms 6092 KB Output is correct
8 Correct 33 ms 6076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 33320 KB Output is correct
2 Correct 258 ms 33372 KB Output is correct
3 Correct 262 ms 33348 KB Output is correct
4 Correct 256 ms 33324 KB Output is correct
5 Correct 261 ms 33328 KB Output is correct
6 Correct 260 ms 33388 KB Output is correct
7 Correct 238 ms 33308 KB Output is correct
8 Correct 230 ms 33280 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 43 ms 6476 KB Output is correct
12 Correct 49 ms 6464 KB Output is correct
13 Correct 37 ms 6320 KB Output is correct
14 Correct 38 ms 6476 KB Output is correct
15 Correct 39 ms 6412 KB Output is correct
16 Correct 43 ms 6416 KB Output is correct
17 Correct 37 ms 6092 KB Output is correct
18 Correct 33 ms 6076 KB Output is correct
19 Correct 301 ms 37372 KB Output is correct
20 Correct 304 ms 37376 KB Output is correct
21 Correct 299 ms 37636 KB Output is correct
22 Correct 295 ms 37420 KB Output is correct
23 Correct 298 ms 37380 KB Output is correct
24 Correct 282 ms 37492 KB Output is correct