답안 #831862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831862 2023-08-20T16:17:20 Z welleyth 분수 공원 (IOI21_parks) C++17
30 / 100
472 ms 57756 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

constexpr int N = (int)3e5+11;

int p[N];

mt19937 rnd(time(nullptr));
int components;

int get(int x){
	return p[x] == x ? x : p[x] = get(p[x]);
}

void union_sets(int a,int b){
	a = get(a), b = get(b);
	if(a == b) return;
	if(rnd()&1) swap(a,b);
	p[a] = b;
	components--;
	return;
}

int construct_roads(std::vector<int> _x, std::vector<int> _y) {
	int n = _x.size();
	components = n;
	for(int i = 0; i < n; i++) p[i] = i;
	vector<pair<int,int>> fountains;
	map<pair<int,int>,int> id;
	for(int i = 0; i < n; i++){
		fountains.push_back(make_pair(_x[i],_y[i]));
		id[fountains.back()] = i;
	}
	sort(fountains.begin(),fountains.end());
	set<pair<int,int>> fountainPositions(fountains.begin(),fountains.end());

	vector<int> g[n];
	vector<pair<int,int>> edges;
	vector<pair<int,int>> coords;
	set<pair<int,int>> benches;
	// shuffle(fountains.begin(),fountains.end(),rnd);

	for(int mask = 0; mask < 1; mask++){
		for(auto&[x,y] : fountains){
			for(int i = -2; i <= 2; i += 2){
				// if((mask & 1) == 0 && i == 2) continue;
				for(int j = -2; j <= 2; j += 2){
					// if((mask >> 1 & 1) == 0 && j == 2) continue;
					if(abs(i) + abs(j) != 2) continue;
					int xn = x + i, yn = y + j;
					int id1 = id[make_pair(x,y)];
					if(!id.count(make_pair(xn,yn))) continue;
					int id2 = id[make_pair(xn,yn)];
					if(get(id1) != get(id2)){
						edges.push_back(make_pair(id1,id2));
						int a,b;
						if(x == xn){
							int my = (y+yn)/2;
							if(!benches.count({x-1,my}))
								a = x-1, b = my;
							else if(!benches.count({x+1,my}))
								a = x+1, b = my;
							else continue;
						} else {
							int mx = (x+xn)/2;
							if(!benches.count({mx,y-1}))
								a = mx, b = y-1;
							else if(!benches.count({mx,y+1}))
								a = mx, b = y+1;
							else continue;
						}
						// cerr << "from " << x << " " << y << ", to " << xn << " " << yn << "\n";
						// cerr << "a,b: " << a << " " << b << "\n";
						coords.push_back(make_pair(a,b));
						benches.insert(make_pair(a,b));
						union_sets(id1,id2);
					}
				}
			}
		}
	}
	
	if(components > 1) return 0;
	vector<int> x,y,a,b;
	for(size_t i = 0; i < edges.size(); i++){
		x.push_back(edges[i].first);
		y.push_back(edges[i].second);
		a.push_back(coords[i].first);
		b.push_back(coords[i].second);
	}
	build(x,y,a,b);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 418 ms 57528 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 5 ms 1144 KB Output is correct
28 Correct 146 ms 23576 KB Output is correct
29 Correct 230 ms 34368 KB Output is correct
30 Correct 328 ms 46992 KB Output is correct
31 Correct 430 ms 57756 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 316 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 179 ms 28512 KB Output is correct
46 Correct 279 ms 42132 KB Output is correct
47 Correct 279 ms 42088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 418 ms 57528 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 5 ms 1144 KB Output is correct
28 Correct 146 ms 23576 KB Output is correct
29 Correct 230 ms 34368 KB Output is correct
30 Correct 328 ms 46992 KB Output is correct
31 Correct 430 ms 57756 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 316 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 179 ms 28512 KB Output is correct
46 Correct 279 ms 42132 KB Output is correct
47 Correct 279 ms 42088 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 312 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 457 ms 57220 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 828 KB Output is correct
58 Correct 11 ms 2132 KB Output is correct
59 Correct 14 ms 2644 KB Output is correct
60 Correct 216 ms 28772 KB Output is correct
61 Correct 282 ms 40028 KB Output is correct
62 Correct 358 ms 48552 KB Output is correct
63 Correct 472 ms 57344 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 382 ms 56604 KB Output is correct
68 Correct 387 ms 57228 KB Output is correct
69 Correct 386 ms 56708 KB Output is correct
70 Correct 6 ms 1236 KB Output is correct
71 Correct 11 ms 2116 KB Output is correct
72 Correct 189 ms 28384 KB Output is correct
73 Correct 298 ms 43452 KB Output is correct
74 Correct 419 ms 56748 KB Output is correct
75 Correct 425 ms 57428 KB Output is correct
76 Correct 401 ms 57280 KB Output is correct
77 Correct 7 ms 1492 KB Output is correct
78 Correct 12 ms 2388 KB Output is correct
79 Correct 184 ms 28464 KB Output is correct
80 Correct 302 ms 43612 KB Output is correct
81 Correct 413 ms 56696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 393 ms 55020 KB Output is correct
21 Correct 395 ms 54976 KB Output is correct
22 Correct 402 ms 55024 KB Output is correct
23 Correct 329 ms 47416 KB Output is correct
24 Correct 249 ms 32404 KB Output is correct
25 Correct 386 ms 44808 KB Output is correct
26 Correct 338 ms 44888 KB Output is correct
27 Correct 391 ms 54960 KB Output is correct
28 Correct 393 ms 55004 KB Output is correct
29 Correct 438 ms 54992 KB Output is correct
30 Correct 426 ms 54968 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 22 ms 3384 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
17 Correct 394 ms 55288 KB Output is correct
18 Correct 403 ms 55152 KB Output is correct
19 Correct 416 ms 55016 KB Output is correct
20 Correct 405 ms 54028 KB Output is correct
21 Correct 359 ms 48600 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Incorrect 45 ms 7192 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 174 ms 27648 KB Output is correct
10 Correct 15 ms 3044 KB Output is correct
11 Correct 99 ms 14984 KB Output is correct
12 Correct 22 ms 4308 KB Output is correct
13 Correct 66 ms 10068 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 176 ms 27652 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 418 ms 57528 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 5 ms 1144 KB Output is correct
28 Correct 146 ms 23576 KB Output is correct
29 Correct 230 ms 34368 KB Output is correct
30 Correct 328 ms 46992 KB Output is correct
31 Correct 430 ms 57756 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 316 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 5 ms 980 KB Output is correct
45 Correct 179 ms 28512 KB Output is correct
46 Correct 279 ms 42132 KB Output is correct
47 Correct 279 ms 42088 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 312 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 457 ms 57220 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 828 KB Output is correct
58 Correct 11 ms 2132 KB Output is correct
59 Correct 14 ms 2644 KB Output is correct
60 Correct 216 ms 28772 KB Output is correct
61 Correct 282 ms 40028 KB Output is correct
62 Correct 358 ms 48552 KB Output is correct
63 Correct 472 ms 57344 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 382 ms 56604 KB Output is correct
68 Correct 387 ms 57228 KB Output is correct
69 Correct 386 ms 56708 KB Output is correct
70 Correct 6 ms 1236 KB Output is correct
71 Correct 11 ms 2116 KB Output is correct
72 Correct 189 ms 28384 KB Output is correct
73 Correct 298 ms 43452 KB Output is correct
74 Correct 419 ms 56748 KB Output is correct
75 Correct 425 ms 57428 KB Output is correct
76 Correct 401 ms 57280 KB Output is correct
77 Correct 7 ms 1492 KB Output is correct
78 Correct 12 ms 2388 KB Output is correct
79 Correct 184 ms 28464 KB Output is correct
80 Correct 302 ms 43612 KB Output is correct
81 Correct 413 ms 56696 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 393 ms 55020 KB Output is correct
86 Correct 395 ms 54976 KB Output is correct
87 Correct 402 ms 55024 KB Output is correct
88 Correct 329 ms 47416 KB Output is correct
89 Correct 249 ms 32404 KB Output is correct
90 Correct 386 ms 44808 KB Output is correct
91 Correct 338 ms 44888 KB Output is correct
92 Correct 391 ms 54960 KB Output is correct
93 Correct 393 ms 55004 KB Output is correct
94 Correct 438 ms 54992 KB Output is correct
95 Correct 426 ms 54968 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 22 ms 3384 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -