답안 #619744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
619744 2022-08-02T15:29:49 Z amunduzbaev 분수 공원 (IOI21_parks) C++17
45 / 100
1004 ms 62716 KB
#include "parks.h"

#include "bits/stdc++.h"
using namespace std;

#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
#define sow cerr<<"start"<<endl;
#define wow cerr<<"end"<<endl;
typedef long long ll;

const int N = 2e5 + 5;
vector<ar<int, 3>> edges[N];

int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	map<ar<int, 2>, int> ss, mm;
	for(int i=0;i<n;i++){
		ss[{x[i], y[i]}] = i;
	}
	
	vector<ar<int, 2>> e, p;
	
	auto add = [&](int a, int b, int p1, int p2){
		edges[a].push_back({b, p1, p2});
		edges[b].push_back({a, p1, p2});
	};
	
	vector<int> par(n), sz(n, 1);
	iota(par.begin(), par.end(), 0);
	function<int(int)> f = [&](int x) { return (par[x] == x ? x : par[x] = f(par[x])); };
	auto merge = [&](int a, int b){
		a = f(a), b = f(b);
		if(a == b) return false;
		if(sz[a] < sz[b]) swap(a, b);
		par[b] = a, sz[a] += sz[b];
		return true;
	};
	
	for(int i=0;i<n;i++){
		if(ss.count({x[i] - 2, y[i]})){
			int j = ss[{x[i] - 2, y[i]}];
			if(merge(i, j)){
				e.push_back({i, j});
				p.push_back({-1, -1});
				int u = e.size() - 1;
				if(mm.count({x[i] - 1, y[i] - 1})){
					int v = mm[{x[i] - 1, y[i] - 1}];
					add(u, v, x[i] - 1, y[i] - 1);
					mm.erase({x[i] - 1, y[i] - 1});
				} else {
					mm[{x[i] - 1, y[i] - 1}] = u;
				}
				if(mm.count({x[i] - 1, y[i] + 1})){
					int v = mm[{x[i] - 1, y[i] + 1}];
					add(u, v, x[i] - 1, y[i] + 1);
					mm.erase({x[i] - 1, y[i] + 1});
				} else {
					mm[{x[i] - 1, y[i] + 1}] = u;
				}
			}
		}
		
		if(ss.count({x[i], y[i] - 2})){
			int j = ss[{x[i], y[i] - 2}];
			if(merge(i, j)){
				e.push_back({i, j});
				p.push_back({-1, -1});
				int u = e.size() - 1;
				if(mm.count({x[i] - 1, y[i] - 1})){
					int v = mm[{x[i] - 1, y[i] - 1}];
					add(u, v, x[i] - 1, y[i] - 1);
					mm.erase({x[i] - 1, y[i] - 1});
				} else {
					mm[{x[i] - 1, y[i] - 1}] = u;
				}
				if(mm.count({x[i] + 1, y[i] - 1})){
					int v = mm[{x[i] + 1, y[i] - 1}];
					add(u, v, x[i] + 1, y[i] - 1);
					mm.erase({x[i] + 1, y[i] - 1});
				} else {
					mm[{x[i] + 1, y[i] - 1}] = u;
				}
			}
		}
	}
	
	
	if(sz[f(0)] < n) {
		//~ assert(false);
		return 0;
	}
	
	int m = e.size();
	
	vector<int> used(m);
	//~ cout<<m<<endl;
	function<void(int)> dfs = [&](int i){
		assert(!used[i]);
		used[i] = 1;
		for(auto [x, p1, p2] : edges[i]){
			if(used[x]) continue;
			p[x] = {p1, p2};
			dfs(x);
		}
	};
	for(auto [x, i] : mm){
		if(used[i]) continue;
		//~ sow
		p[i] = x;
		dfs(i);
		//~ wow
	}
	for(int i=0;i<m;i++){
		if(used[i]) continue;
		p[i] = {edges[i].back()[1], edges[i].back()[2]};
		edges[i].pop_back();
		
		dfs(i);
	}
	
	vector<int> u(m), v(m), A(m), B(m);
	for(int i=0;i<m;i++){
		u[i] = e[i][0], v[i] = e[i][1];
		A[i] = p[i][0], B[i] = p[i][1];
	}
	
	build(u, v, A, B);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 5000 KB Output is correct
19 Correct 3 ms 5000 KB Output is correct
20 Correct 745 ms 57820 KB Output is correct
21 Correct 936 ms 53524 KB Output is correct
22 Correct 789 ms 51136 KB Output is correct
23 Correct 663 ms 53968 KB Output is correct
24 Correct 312 ms 23884 KB Output is correct
25 Correct 807 ms 51896 KB Output is correct
26 Correct 792 ms 51956 KB Output is correct
27 Correct 874 ms 62124 KB Output is correct
28 Correct 927 ms 62168 KB Output is correct
29 Correct 926 ms 62092 KB Output is correct
30 Correct 940 ms 62072 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 37 ms 8352 KB Output is correct
33 Correct 102 ms 14860 KB Output is correct
34 Correct 811 ms 60068 KB Output is correct
35 Correct 22 ms 6732 KB Output is correct
36 Correct 157 ms 13368 KB Output is correct
37 Correct 349 ms 21920 KB Output is correct
38 Correct 274 ms 22868 KB Output is correct
39 Correct 400 ms 29204 KB Output is correct
40 Correct 611 ms 35876 KB Output is correct
41 Correct 812 ms 42440 KB Output is correct
42 Correct 1004 ms 49008 KB Output is correct
43 Correct 4 ms 4948 KB Output is correct
44 Correct 3 ms 4948 KB Output is correct
45 Correct 3 ms 4948 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 3 ms 4948 KB Output is correct
49 Correct 3 ms 5000 KB Output is correct
50 Correct 3 ms 5000 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 5000 KB Output is correct
54 Correct 6 ms 5332 KB Output is correct
55 Correct 7 ms 5560 KB Output is correct
56 Correct 345 ms 28696 KB Output is correct
57 Correct 555 ms 39340 KB Output is correct
58 Correct 551 ms 39500 KB Output is correct
59 Correct 3 ms 4948 KB Output is correct
60 Correct 3 ms 4948 KB Output is correct
61 Correct 3 ms 5004 KB Output is correct
62 Correct 844 ms 62192 KB Output is correct
63 Correct 862 ms 62144 KB Output is correct
64 Correct 817 ms 61848 KB Output is correct
65 Correct 9 ms 5716 KB Output is correct
66 Correct 17 ms 6356 KB Output is correct
67 Correct 372 ms 28096 KB Output is correct
68 Correct 635 ms 39524 KB Output is correct
69 Correct 928 ms 51252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
17 Correct 872 ms 62580 KB Output is correct
18 Correct 856 ms 62716 KB Output is correct
19 Correct 836 ms 58628 KB Output is correct
20 Correct 902 ms 47796 KB Output is correct
21 Correct 821 ms 49316 KB Output is correct
22 Correct 3 ms 4936 KB Output is correct
23 Correct 96 ms 12444 KB Output is correct
24 Correct 44 ms 8408 KB Output is correct
25 Correct 200 ms 17448 KB Output is correct
26 Correct 477 ms 25732 KB Output is correct
27 Correct 393 ms 27316 KB Output is correct
28 Correct 571 ms 33072 KB Output is correct
29 Correct 713 ms 38720 KB Output is correct
30 Correct 920 ms 44028 KB Output is correct
31 Correct 998 ms 49828 KB Output is correct
32 Correct 931 ms 53680 KB Output is correct
33 Correct 832 ms 62216 KB Output is correct
34 Correct 10 ms 5844 KB Output is correct
35 Correct 21 ms 6740 KB Output is correct
36 Correct 345 ms 28128 KB Output is correct
37 Correct 661 ms 39924 KB Output is correct
38 Correct 961 ms 51460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4992 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4996 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 343 ms 33536 KB Output is correct
10 Correct 18 ms 7860 KB Output is correct
11 Correct 108 ms 20288 KB Output is correct
12 Correct 32 ms 9200 KB Output is correct
13 Correct 69 ms 15324 KB Output is correct
14 Correct 4 ms 5204 KB Output is correct
15 Correct 5 ms 5460 KB Output is correct
16 Correct 335 ms 33528 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Incorrect 3 ms 4948 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 2
19 Halted 0 ms 0 KB -