답안 #1044720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1044720 2024-08-05T12:47:35 Z s_tree 분수 공원 (IOI21_parks) C++17
45 / 100
726 ms 38144 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
struct dsu {
	vector<int> e;
	int cc=0;
	dsu(int n) {
		cc=n;
		e=vector<int>(n+1, -1);
	}
	int get(int x) {return e[x]<0?x:e[x]=get(e[x]);}
	bool unite(int a, int b) {
		a=get(a),b=get(b);
		if(a==b)return false;
		if(-e[a] > -e[b]) {
			swap(a, b);
		}
		e[b]+=e[a];
		e[a]=b;
		cc--;
//		cout << a << " " << b << endl;
		return true;
	}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = x.size();
	map<pair<int,int>, int> mp;
	vector<pair<int,int>> ben;
	for(int i = 0;i<n;i++) {
		mp[{x[i], y[i]}] = i;
	}
	vector<pair<int,int>> blB, whB;
	dsu d(n);
	for(int i = 0;i<n;i++) {
		ben.pb({x[i]+1, y[i]+1});
		ben.pb({x[i]-1, y[i]+1});
		ben.pb({x[i]+1, y[i]-1});
		ben.pb({x[i]-1, y[i]-1});
		if(mp.find(pair{x[i]+2, y[i]})!=mp.end()) {
			d.unite(mp[{x[i]+2, y[i]}], i);
		}
		if(mp.find(pair{x[i], y[i]+2})!=mp.end()) {
			d.unite(mp[{x[i], y[i]+2}], i);
		}
	}
	if(d.cc!=1)return 0;
	dsu d2(n+1);
	vector<int> a, b, c,D ;
	for(auto [xx, yy]:ben) {
		if((xx+yy)%4 == 0) {
			pair<int,int> A = {xx+1, yy+1};
			pair<int,int> B = {xx+1, yy-1};
			if(mp.find(A)!=mp.end() and mp.find(B)!=mp.end() and d2.unite(mp[A], mp[B])) {
				a.push_back(mp[A]);
				b.push_back(mp[B]);
				c.push_back(xx);
				D.push_back(yy);
				continue;
			}
			A.first-=2, B.first-=2;
			if(mp.find(A)!=mp.end() and mp.find(B)!=mp.end() and d2.unite(mp[A], mp[B])) {
				a.push_back(mp[A]);
				b.push_back(mp[B]);
				c.push_back(xx);
				D.push_back(yy);
				continue;
			}
		}
		else {
			pair<int,int> A = {xx+1, yy+1};
			pair<int,int> B = {xx-1, yy+1};
			if(mp.find(A)!=mp.end() and mp.find(B)!=mp.end() and d2.unite(mp[A], mp[B])) {
				a.push_back(mp[A]);
				b.push_back(mp[B]);
				c.push_back(xx);
				D.push_back(yy);
				continue;
			}
			A.second-=2, B.second-=2;
			if(mp.find(A)!=mp.end() and mp.find(B)!=mp.end() and d2.unite(mp[A], mp[B])) {
				a.push_back(mp[A]);
				b.push_back(mp[B]);
				c.push_back(xx);
				D.push_back(yy);
				continue;
			}
		}
	}
	build(a, b, c, D);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
17 Incorrect 1 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
17 Incorrect 1 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 568 ms 35552 KB Output is correct
21 Correct 572 ms 35520 KB Output is correct
22 Correct 582 ms 38136 KB Output is correct
23 Correct 411 ms 32176 KB Output is correct
24 Correct 133 ms 28168 KB Output is correct
25 Correct 189 ms 27024 KB Output is correct
26 Correct 172 ms 27584 KB Output is correct
27 Correct 547 ms 36788 KB Output is correct
28 Correct 587 ms 35768 KB Output is correct
29 Correct 582 ms 36616 KB Output is correct
30 Correct 611 ms 36472 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 32 ms 2796 KB Output is correct
33 Correct 63 ms 14752 KB Output is correct
34 Correct 575 ms 38144 KB Output is correct
35 Correct 7 ms 2008 KB Output is correct
36 Correct 38 ms 7276 KB Output is correct
37 Correct 84 ms 14020 KB Output is correct
38 Correct 235 ms 15880 KB Output is correct
39 Correct 335 ms 20092 KB Output is correct
40 Correct 446 ms 27328 KB Output is correct
41 Correct 559 ms 32688 KB Output is correct
42 Correct 671 ms 37376 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 246 ms 17892 KB Output is correct
57 Correct 376 ms 27800 KB Output is correct
58 Correct 391 ms 27060 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 439 ms 37152 KB Output is correct
63 Correct 422 ms 35768 KB Output is correct
64 Correct 440 ms 35764 KB Output is correct
65 Correct 2 ms 856 KB Output is correct
66 Correct 4 ms 1504 KB Output is correct
67 Correct 271 ms 18752 KB Output is correct
68 Correct 469 ms 28216 KB Output is correct
69 Correct 580 ms 37564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
17 Correct 484 ms 35432 KB Output is correct
18 Correct 482 ms 35440 KB Output is correct
19 Correct 565 ms 37164 KB Output is correct
20 Correct 726 ms 35052 KB Output is correct
21 Correct 575 ms 32948 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 82 ms 5724 KB Output is correct
24 Correct 14 ms 3284 KB Output is correct
25 Correct 63 ms 12740 KB Output is correct
26 Correct 109 ms 17356 KB Output is correct
27 Correct 317 ms 18876 KB Output is correct
28 Correct 409 ms 22680 KB Output is correct
29 Correct 516 ms 29876 KB Output is correct
30 Correct 626 ms 33468 KB Output is correct
31 Correct 698 ms 37984 KB Output is correct
32 Correct 570 ms 36540 KB Output is correct
33 Correct 434 ms 36980 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 5 ms 1752 KB Output is correct
36 Correct 270 ms 18556 KB Output is correct
37 Correct 444 ms 28248 KB Output is correct
38 Correct 602 ms 36852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 191 ms 18736 KB Output is correct
10 Correct 14 ms 2000 KB Output is correct
11 Correct 81 ms 9856 KB Output is correct
12 Correct 19 ms 3024 KB Output is correct
13 Correct 21 ms 6604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 219 ms 17776 KB Output is correct
17 Incorrect 1 ms 344 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -