답안 #1053211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053211 2024-08-11T09:46:19 Z tolbi 분수 공원 (IOI21_parks) C++17
55 / 100
932 ms 114764 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
//void build(std::vector<int> u, std::vector<int> v, std::vector<int> a, std::vector<int> b);
struct DSU{
	vector<int> par;
	int tot;
	DSU(int n):tot(n){
		par.resize(n);
		iota(par.begin(), par.end(), 0);
	}
	int find(int node){
		if (par[node]==node) return node;
		return par[node]=find(par[node]);
	}
	bool merge(int a, int b){
		a=find(a);
		b=find(b);
		if (a!=b) tot--;
		else return false;
		par[a]=b;
		return true;
	}
};
int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();


	//subtasks 4..5
	DSU dsu(n);
	map<pair<int,int>,int> mp;
	for (int i = 0; i < n; ++i)
	{
		mp[{x[i],y[i]}]=i;
	}
	vector<int> u;
	vector<int> v;
	vector<int> xa(n-1,-1);
	vector<int> ya(n-1,-1);
	vector<set<pair<int,int>>> arr;
	map<pair<int,int>,set<int>> qu;
	for (int i = 0; i < n; ++i)
	{
		if (mp.count({x[i]-2,y[i]})){
			if (dsu.merge(mp[{x[i]-2,y[i]}],i)){
				u.push_back(mp[{x[i]-2,y[i]}]);
				v.push_back(i);
				arr.push_back(set<pair<int,int>>());
				arr.back().insert({x[i]-1,y[i]-1});
				arr.back().insert({x[i]-1,y[i]+1});
				qu[{x[i]-1,y[i]-1}].insert((int)u.size()-1);
				qu[{x[i]-1,y[i]+1}].insert((int)u.size()-1);
			}
		}
		if (mp.count({x[i],y[i]-2})){
			if (dsu.merge(mp[{x[i],y[i]-2}],i)){
				u.push_back(mp[{x[i],y[i]-2}]);
				v.push_back(i);
				arr.push_back(set<pair<int,int>>());
				arr.back().insert({x[i]-1,y[i]-1});
				arr.back().insert({x[i]+1,y[i]-1});
				qu[{x[i]-1,y[i]-1}].insert((int)u.size()-1);
				qu[{x[i]+1,y[i]-1}].insert((int)u.size()-1);
			}
		}
	}
	if (dsu.tot!=1) return 0;
	vector<pair<int,int>> iki;
	queue<pair<int,int>> que;
	int kal = n-1;
	for (auto it : qu){
		if (it.second.size()==1) que.push(it.first);
		else iki.push_back(it.first);
	}
	set<pair<int,int>> lmao;
	while (kal>0){
		while (que.size() && (qu[que.front()].size()<1 || lmao.find(que.front())!=lmao.end())) que.pop();
		if (!que.size()){
			while (iki.size() && qu[iki.back()].size()<2) iki.pop_back();
			if (iki.size()){
				int it = *qu[iki.back()].begin();
				arr[it].erase(iki.back());
				qu[iki.back()].erase(it);
				que.push(iki.back());
				iki.pop_back();
			}
			else return 0;
		}
		if (!que.size()) return 0;
		pair<int,int> pr = que.front();
		que.pop();
		int it = *qu[pr].begin();
		if (xa[it]!=-1) continue;
		kal--;
		lmao.insert(pr);
		xa[it]=pr.first, ya[it]=pr.second;
		for (auto it2 : arr[it]){
			if (qu[it2].find(it)!=qu[it2].end()) qu[it2].erase(it);
			if (qu[it2].size()==1) {
				que.push(it2);
			}
		}
		while (arr[it].size()) arr[it].erase(arr[it].begin());
	}
	build(u,v,xa,ya);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 855 ms 98972 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 984 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 5 ms 2216 KB Output is correct
28 Correct 239 ms 39696 KB Output is correct
29 Correct 485 ms 58616 KB Output is correct
30 Correct 647 ms 78568 KB Output is correct
31 Correct 840 ms 97772 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 3 ms 1628 KB Output is correct
45 Correct 354 ms 52468 KB Output is correct
46 Correct 589 ms 74228 KB Output is correct
47 Correct 574 ms 75508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 855 ms 98972 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 984 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 5 ms 2216 KB Output is correct
28 Correct 239 ms 39696 KB Output is correct
29 Correct 485 ms 58616 KB Output is correct
30 Correct 647 ms 78568 KB Output is correct
31 Correct 840 ms 97772 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 3 ms 1628 KB Output is correct
45 Correct 354 ms 52468 KB Output is correct
46 Correct 589 ms 74228 KB Output is correct
47 Correct 574 ms 75508 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 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Incorrect 832 ms 90180 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 669 ms 94856 KB Output is correct
21 Correct 768 ms 95528 KB Output is correct
22 Correct 713 ms 94956 KB Output is correct
23 Correct 690 ms 98284 KB Output is correct
24 Correct 141 ms 18340 KB Output is correct
25 Correct 535 ms 105864 KB Output is correct
26 Correct 585 ms 104424 KB Output is correct
27 Correct 897 ms 114572 KB Output is correct
28 Correct 873 ms 114392 KB Output is correct
29 Correct 809 ms 113136 KB Output is correct
30 Correct 801 ms 114164 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 33 ms 7220 KB Output is correct
33 Correct 59 ms 9220 KB Output is correct
34 Correct 740 ms 96600 KB Output is correct
35 Correct 13 ms 4884 KB Output is correct
36 Correct 89 ms 22668 KB Output is correct
37 Correct 209 ms 44884 KB Output is correct
38 Correct 259 ms 41508 KB Output is correct
39 Correct 441 ms 54644 KB Output is correct
40 Correct 565 ms 69616 KB Output is correct
41 Correct 746 ms 85996 KB Output is correct
42 Correct 903 ms 99552 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 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 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 2 ms 1116 KB Output is correct
55 Correct 3 ms 1628 KB Output is correct
56 Correct 326 ms 51220 KB Output is correct
57 Correct 584 ms 74824 KB Output is correct
58 Correct 568 ms 75452 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 851 ms 114764 KB Output is correct
63 Correct 844 ms 114400 KB Output is correct
64 Correct 828 ms 113356 KB Output is correct
65 Correct 5 ms 2136 KB Output is correct
66 Correct 9 ms 4000 KB Output is correct
67 Correct 363 ms 51728 KB Output is correct
68 Correct 594 ms 75764 KB Output is correct
69 Correct 890 ms 101868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
17 Correct 817 ms 114416 KB Output is correct
18 Correct 831 ms 114168 KB Output is correct
19 Correct 738 ms 95788 KB Output is correct
20 Correct 830 ms 97552 KB Output is correct
21 Correct 724 ms 95036 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 82 ms 15628 KB Output is correct
24 Correct 31 ms 9420 KB Output is correct
25 Correct 131 ms 34560 KB Output is correct
26 Correct 292 ms 54508 KB Output is correct
27 Correct 361 ms 49656 KB Output is correct
28 Correct 500 ms 62204 KB Output is correct
29 Correct 666 ms 74480 KB Output is correct
30 Correct 809 ms 88564 KB Output is correct
31 Correct 912 ms 100444 KB Output is correct
32 Correct 924 ms 104168 KB Output is correct
33 Correct 807 ms 113904 KB Output is correct
34 Correct 6 ms 2712 KB Output is correct
35 Correct 11 ms 4656 KB Output is correct
36 Correct 364 ms 51740 KB Output is correct
37 Correct 630 ms 76784 KB Output is correct
38 Correct 932 ms 101876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 347 ms 57536 KB Output is correct
10 Correct 17 ms 5908 KB Output is correct
11 Correct 122 ms 30816 KB Output is correct
12 Correct 27 ms 8716 KB Output is correct
13 Correct 47 ms 23720 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 322 ms 56836 KB Output is correct
17 Correct 0 ms 600 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 855 ms 98972 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 2 ms 984 KB Output is correct
26 Correct 3 ms 1628 KB Output is correct
27 Correct 5 ms 2216 KB Output is correct
28 Correct 239 ms 39696 KB Output is correct
29 Correct 485 ms 58616 KB Output is correct
30 Correct 647 ms 78568 KB Output is correct
31 Correct 840 ms 97772 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 2 ms 1116 KB Output is correct
44 Correct 3 ms 1628 KB Output is correct
45 Correct 354 ms 52468 KB Output is correct
46 Correct 589 ms 74228 KB Output is correct
47 Correct 574 ms 75508 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 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Incorrect 832 ms 90180 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -