답안 #827017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827017 2023-08-16T08:01:16 Z NothingXD 분수 공원 (IOI21_parks) C++17
15 / 100
456 ms 98100 KB
#include "parks.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 2e5 + 10;

int n, x[maxn], y[maxn], dsu[maxn], cntedge[maxn], cntdot[maxn<<1], a[maxn], b[maxn];
vector<int> numx[maxn], numy[maxn];
vector<pair<pii,int>> p;
vector<pii> edge;
vector<pii> dot;
vector<int> gedge[maxn], gdot[maxn<<1];
bool markedge[maxn];
bool markdot[maxn];
set<pii> st;
int getdsu(int v){
	return (dsu[v] < 0? v: dsu[v] = getdsu(dsu[v]));
}

bool merge(int u, int v){
	if ((u = getdsu(u)) == (v = getdsu(v))) return false;
	dsu[u] = v;
	return true;
}

pair<pii,pii> getdot(int u, int v){
	//debug(x[u], x[v], y[u], y[v]);
	if (x[u] == x[v]) return {{x[u]-1, (y[u]+y[v])/2}, {x[u]+1, (y[u]+y[v])/2}};
	return {{(x[u]+x[v])/2, y[u]-1}, {(x[u]+x[v])/2, y[u]+1}};
}

void rmdot(int idx){
	for (auto x: gdot[idx]){
		if (!markedge[x]){
			st.erase({cntedge[x], x});
			cntedge[x]--;
			st.insert({cntedge[x], x});
		}
	}
}

void rmedge(int idx){
	for (auto x: gedge[idx]){
		if (!markdot[x]){
			st.erase({cntdot[x], x+n});
			cntdot[x]--;
			st.insert({cntdot[x], x+n});
		}
	}
}


int construct_roads(std::vector<int> X, std::vector<int> Y) {
	memset(dsu, -1, sizeof dsu);
	n = X.size();
	for (int i = 0; i < n; i++){
		x[i] = X[i];
		y[i] = Y[i];
		p.push_back({{X[i], Y[i]}, i});
		numx[X[i]].push_back(Y[i]);
		numy[Y[i]].push_back(X[i]);
	}
	sort(all(p));
	for (int i = 0; i < maxn; i++){
		sort(all(numx[i]));
		for (int j = 1; j < numx[i].size(); j++){
			if (numx[i][j-1] + 2 == numx[i][j]){
				int u = (*lower_bound(all(p), MP(MP(i, numx[i][j-1]), 0))).S;
				int v = (*lower_bound(all(p), MP(MP(i, numx[i][j]), 0))).S;
				if (merge(u, v)) edge.push_back({u, v});
			}
		}
		sort(all(numy[i]));
		for (int j = 1; j < numy[i].size(); j++){
			if (numy[i][j-1] + 2 == numy[i][j]){
				int u = (*lower_bound(all(p), MP(MP(numy[i][j-1], i), 0))).S;
				int v = (*lower_bound(all(p), MP(MP(numy[i][j], i), 0))).S;
				if (merge(u, v)) edge.push_back({u, v});
			}
		}
	}
	if (edge.size() != n-1) return 0;
	for (int i = 0; i < n-1; i++){
		pair<pii,pii> tmp = getdot(edge[i].F, edge[i].S);
//		debug(edge[i].F, edge[i].S, tmp.F.F, tmp.F.S, tmp.S.F, tmp.S.S);
		dot.push_back(tmp.F);
		dot.push_back(tmp.S);
	}
	sort(all(dot));
	dot.resize(distance(dot.begin(), unique(all(dot))));
	for (int i = 0; i < n-1; i++){
		cntedge[i] = 2;
		pair<pii,pii> tmp = getdot(edge[i].F, edge[i].S);
		int idx = lower_bound(all(dot), tmp.F) - dot.begin();
	//	debug(i, idx);
		gdot[idx].push_back(i);
		gedge[i].push_back(idx);
		cntdot[idx]++;
		idx = lower_bound(all(dot), tmp.S) - dot.begin();
	//	debug(i, idx);
		gdot[idx].push_back(i);
		gedge[i].push_back(idx);
		cntdot[idx]++;
	}
	for (int i = 0; i < n-1; i++){
	//	debug(i, edge[i].F, edge[i].S, cntedge[i]);
		st.insert({cntedge[i], i});
	}
	for (int i = 0; i < dot.size(); i++){
		//debug(i, dot[i].F, dot[i].S, cntdot[i]);
		st.insert({cntdot[i], n+i});
	}
	while(!st.empty()){
		pii v = *st.begin();
		st.erase(st.begin());
		//debug(v.F, v.S);
		if (v.F == 0){
			assert(v.S >= n);
			continue;
		}
		if (v.S > n){
			v.S -= n;
			markdot[v.S] = true;
			for (auto x: gdot[v.S]){
//				debug(x);
				if (!markedge[x]){
//					debug(x, v.S);
					markedge[x] = true;
					a[x] = dot[v.S].F;
					b[x] = dot[v.S].S;
					st.erase({cntedge[x], x});
					rmdot(v.S);
					rmedge(x);
					break;
				}
			}
		}
		else{
			markedge[v.S] = true;
			for (auto x: gedge[v.S]){
				if (!markdot[x]){
//					debug(v.S, x);
					markdot[x] = true;
					a[v.S] = dot[x].F;
					b[v.S] = dot[x].S;
					st.erase({cntdot[x], x+n});
					rmdot(x);
					rmedge(v.S);
					break;
				}
			}
		}
	}
	vector<int> U, V, A, B;
	for (int i = 0; i < n-1; i++){
		U.push_back(edge[i].F);
		V.push_back(edge[i].S);
		A.push_back(a[i]);
		B.push_back(b[i]);
	}
	build(U, V, A, B);
	return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for (int j = 1; j < numx[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~
parks.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |   for (int j = 1; j < numy[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~~
parks.cpp:100:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |  if (edge.size() != n-1) return 0;
      |      ~~~~~~~~~~~~^~~~~~
parks.cpp:127:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |  for (int i = 0; i < dot.size(); i++){
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
17 Correct 14 ms 24532 KB Output is correct
18 Correct 15 ms 24580 KB Output is correct
19 Correct 13 ms 24532 KB Output is correct
20 Correct 14 ms 24532 KB Output is correct
21 Correct 14 ms 24532 KB Output is correct
22 Correct 14 ms 24532 KB Output is correct
23 Correct 403 ms 89156 KB Output is correct
24 Correct 13 ms 24532 KB Output is correct
25 Correct 16 ms 24872 KB Output is correct
26 Correct 16 ms 24828 KB Output is correct
27 Correct 18 ms 24792 KB Output is correct
28 Correct 162 ms 50196 KB Output is correct
29 Correct 251 ms 63480 KB Output is correct
30 Correct 341 ms 76264 KB Output is correct
31 Correct 417 ms 89200 KB Output is correct
32 Correct 14 ms 24608 KB Output is correct
33 Correct 14 ms 24580 KB Output is correct
34 Correct 14 ms 24508 KB Output is correct
35 Correct 14 ms 24472 KB Output is correct
36 Correct 13 ms 24536 KB Output is correct
37 Correct 15 ms 24488 KB Output is correct
38 Correct 14 ms 24532 KB Output is correct
39 Correct 14 ms 24532 KB Output is correct
40 Correct 14 ms 24532 KB Output is correct
41 Correct 16 ms 24520 KB Output is correct
42 Correct 16 ms 24560 KB Output is correct
43 Correct 16 ms 24752 KB Output is correct
44 Correct 15 ms 24788 KB Output is correct
45 Correct 231 ms 55668 KB Output is correct
46 Correct 303 ms 69756 KB Output is correct
47 Correct 303 ms 69772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
17 Correct 14 ms 24532 KB Output is correct
18 Correct 15 ms 24580 KB Output is correct
19 Correct 13 ms 24532 KB Output is correct
20 Correct 14 ms 24532 KB Output is correct
21 Correct 14 ms 24532 KB Output is correct
22 Correct 14 ms 24532 KB Output is correct
23 Correct 403 ms 89156 KB Output is correct
24 Correct 13 ms 24532 KB Output is correct
25 Correct 16 ms 24872 KB Output is correct
26 Correct 16 ms 24828 KB Output is correct
27 Correct 18 ms 24792 KB Output is correct
28 Correct 162 ms 50196 KB Output is correct
29 Correct 251 ms 63480 KB Output is correct
30 Correct 341 ms 76264 KB Output is correct
31 Correct 417 ms 89200 KB Output is correct
32 Correct 14 ms 24608 KB Output is correct
33 Correct 14 ms 24580 KB Output is correct
34 Correct 14 ms 24508 KB Output is correct
35 Correct 14 ms 24472 KB Output is correct
36 Correct 13 ms 24536 KB Output is correct
37 Correct 15 ms 24488 KB Output is correct
38 Correct 14 ms 24532 KB Output is correct
39 Correct 14 ms 24532 KB Output is correct
40 Correct 14 ms 24532 KB Output is correct
41 Correct 16 ms 24520 KB Output is correct
42 Correct 16 ms 24560 KB Output is correct
43 Correct 16 ms 24752 KB Output is correct
44 Correct 15 ms 24788 KB Output is correct
45 Correct 231 ms 55668 KB Output is correct
46 Correct 303 ms 69756 KB Output is correct
47 Correct 303 ms 69772 KB Output is correct
48 Correct 14 ms 24532 KB Output is correct
49 Correct 13 ms 24564 KB Output is correct
50 Correct 14 ms 24564 KB Output is correct
51 Correct 14 ms 24532 KB Output is correct
52 Correct 14 ms 24560 KB Output is correct
53 Correct 14 ms 24532 KB Output is correct
54 Correct 15 ms 24564 KB Output is correct
55 Correct 396 ms 84828 KB Output is correct
56 Correct 14 ms 24608 KB Output is correct
57 Correct 18 ms 25128 KB Output is correct
58 Correct 27 ms 26324 KB Output is correct
59 Correct 22 ms 25408 KB Output is correct
60 Correct 199 ms 54672 KB Output is correct
61 Correct 278 ms 65072 KB Output is correct
62 Correct 348 ms 74500 KB Output is correct
63 Correct 427 ms 84956 KB Output is correct
64 Correct 14 ms 24532 KB Output is correct
65 Correct 14 ms 24560 KB Output is correct
66 Correct 15 ms 24560 KB Output is correct
67 Correct 445 ms 95760 KB Output is correct
68 Correct 456 ms 97356 KB Output is correct
69 Correct 420 ms 96228 KB Output is correct
70 Correct 16 ms 24792 KB Output is correct
71 Correct 18 ms 25172 KB Output is correct
72 Correct 229 ms 54416 KB Output is correct
73 Correct 325 ms 69732 KB Output is correct
74 Incorrect 427 ms 84720 KB a[48194] = 0 is not an odd integer
75 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
17 Correct 13 ms 24532 KB Output is correct
18 Correct 14 ms 24532 KB Output is correct
19 Correct 14 ms 24580 KB Output is correct
20 Correct 424 ms 83104 KB Output is correct
21 Correct 372 ms 79880 KB Output is correct
22 Correct 441 ms 79964 KB Output is correct
23 Incorrect 373 ms 85844 KB a[48008] = 0 is not an odd integer
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
17 Incorrect 425 ms 98100 KB a[100000] = 0 is not an odd integer
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 24532 KB Output is correct
2 Correct 14 ms 24548 KB Output is correct
3 Correct 17 ms 24672 KB Output is correct
4 Correct 16 ms 24596 KB Output is correct
5 Correct 13 ms 24504 KB Output is correct
6 Correct 13 ms 24532 KB Output is correct
7 Correct 13 ms 24588 KB Output is correct
8 Correct 14 ms 24548 KB Output is correct
9 Correct 212 ms 61676 KB Output is correct
10 Correct 30 ms 28352 KB Output is correct
11 Correct 107 ms 44472 KB Output is correct
12 Correct 37 ms 30200 KB Output is correct
13 Correct 29 ms 28844 KB Output is correct
14 Correct 14 ms 24596 KB Output is correct
15 Correct 14 ms 24660 KB Output is correct
16 Correct 211 ms 61792 KB Output is correct
17 Correct 14 ms 24532 KB Output is correct
18 Correct 15 ms 24580 KB Output is correct
19 Correct 13 ms 24532 KB Output is correct
20 Correct 14 ms 24532 KB Output is correct
21 Correct 14 ms 24532 KB Output is correct
22 Correct 14 ms 24532 KB Output is correct
23 Correct 403 ms 89156 KB Output is correct
24 Correct 13 ms 24532 KB Output is correct
25 Correct 16 ms 24872 KB Output is correct
26 Correct 16 ms 24828 KB Output is correct
27 Correct 18 ms 24792 KB Output is correct
28 Correct 162 ms 50196 KB Output is correct
29 Correct 251 ms 63480 KB Output is correct
30 Correct 341 ms 76264 KB Output is correct
31 Correct 417 ms 89200 KB Output is correct
32 Correct 14 ms 24608 KB Output is correct
33 Correct 14 ms 24580 KB Output is correct
34 Correct 14 ms 24508 KB Output is correct
35 Correct 14 ms 24472 KB Output is correct
36 Correct 13 ms 24536 KB Output is correct
37 Correct 15 ms 24488 KB Output is correct
38 Correct 14 ms 24532 KB Output is correct
39 Correct 14 ms 24532 KB Output is correct
40 Correct 14 ms 24532 KB Output is correct
41 Correct 16 ms 24520 KB Output is correct
42 Correct 16 ms 24560 KB Output is correct
43 Correct 16 ms 24752 KB Output is correct
44 Correct 15 ms 24788 KB Output is correct
45 Correct 231 ms 55668 KB Output is correct
46 Correct 303 ms 69756 KB Output is correct
47 Correct 303 ms 69772 KB Output is correct
48 Correct 14 ms 24532 KB Output is correct
49 Correct 13 ms 24564 KB Output is correct
50 Correct 14 ms 24564 KB Output is correct
51 Correct 14 ms 24532 KB Output is correct
52 Correct 14 ms 24560 KB Output is correct
53 Correct 14 ms 24532 KB Output is correct
54 Correct 15 ms 24564 KB Output is correct
55 Correct 396 ms 84828 KB Output is correct
56 Correct 14 ms 24608 KB Output is correct
57 Correct 18 ms 25128 KB Output is correct
58 Correct 27 ms 26324 KB Output is correct
59 Correct 22 ms 25408 KB Output is correct
60 Correct 199 ms 54672 KB Output is correct
61 Correct 278 ms 65072 KB Output is correct
62 Correct 348 ms 74500 KB Output is correct
63 Correct 427 ms 84956 KB Output is correct
64 Correct 14 ms 24532 KB Output is correct
65 Correct 14 ms 24560 KB Output is correct
66 Correct 15 ms 24560 KB Output is correct
67 Correct 445 ms 95760 KB Output is correct
68 Correct 456 ms 97356 KB Output is correct
69 Correct 420 ms 96228 KB Output is correct
70 Correct 16 ms 24792 KB Output is correct
71 Correct 18 ms 25172 KB Output is correct
72 Correct 229 ms 54416 KB Output is correct
73 Correct 325 ms 69732 KB Output is correct
74 Incorrect 427 ms 84720 KB a[48194] = 0 is not an odd integer
75 Halted 0 ms 0 KB -