답안 #773466

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773466 2023-07-05T05:43:50 Z SanguineChameleon 분수 공원 (IOI21_parks) C++17
45 / 100
925 ms 104600 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 20;
vector<int> adj[maxn * 3];
bool flag[maxn * 3];
map<pair<int, int>, int> even_id;
map<pair<int, int>, int> odd_id;
vector<pair<int, int>> odds;
vector<pair<int, int>> roads;
int node_cnt;
int road_cnt;
vector<int> path;

int get_even_id(int x, int y) {
	auto it = even_id.find(make_pair(x, y));
	if (it == even_id.end()) {
		return -1;
	}
	else {
		return it->second;
	}
}

int get_odd_id(int x, int y) {
	auto it = odd_id.find(make_pair(x, y));
	if (it != odd_id.end()) {
		return it->second;
	}
	else {
		odds.emplace_back(x, y);
		return odd_id[make_pair(x, y)] = node_cnt++;
	}
}

void add_edge(int u, int v) {
	adj[u].push_back(v);
	adj[v].push_back(u);
}

void dfs(int u) {
	flag[u] = true;
	path.push_back(u);
	for (auto v: adj[u]) {
		if (!flag[v]) {
			dfs(v);
		}
	}
}

int construct_roads(vector<int> x, vector<int> y) {
	int n = x.size();
	for (int i = 0; i < n; i++) {
		even_id[make_pair(x[i], y[i])] = i;
	}
	for (int u = 0; u < n; u++) {
		int v = get_even_id(x[u] + 2, y[u]);
		if (v != -1) {
			roads.emplace_back(u, v);
			add_edge(u, v);
		}
		v = get_even_id(x[u], y[u] + 2);
		if (v != -1) {
			roads.emplace_back(u, v);
			add_edge(u, v);
		}
	}
	dfs(0);
	for (int i = 0; i < n; i++) {
		if (!flag[i]) {
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		adj[i].clear();
	}
	road_cnt = roads.size();
	node_cnt = road_cnt;
	for (int i = 0; i < road_cnt; i++) {
		int u = roads[i].first;
		int v = roads[i].second;
		if (y[u] == y[v]) {
			add_edge(i, get_odd_id(x[u] + 1, y[u] - 1));
			add_edge(i, get_odd_id(x[u] + 1, y[u] + 1));
		}
		else {
			add_edge(i, get_odd_id(x[u] - 1, y[u] + 1));
			add_edge(i, get_odd_id(x[u] + 1, y[u] + 1));
		}
	}
	vector<int> u, v, a, b;
	for (int i = 0; i < node_cnt; i++) {
		flag[i] = false;
	}
	for (int iter = 0; iter < 2; iter++) {
		for (int i = road_cnt; i < node_cnt; i++) {
			if (!flag[i] && (iter == 1 || (int)adj[i].size() == 1)) {
				path.clear();
				dfs(i);
				for (int j = 0; j + 1 < (int)path.size(); j += 2) {
					u.push_back(roads[path[j + 1]].first);
					v.push_back(roads[path[j + 1]].second);
					a.push_back(odds[path[j] - road_cnt].first);
					b.push_back(odds[path[j] - road_cnt].second);
				}
			}
		}
	}
	build(u, v, a, b);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
17 Incorrect 7 ms 14404 KB Tree (a[2], b[2]) = (5, 3) is not adjacent to edge between u[2]=3 @(2, 2) and v[2]=2 @(4, 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
17 Incorrect 7 ms 14404 KB Tree (a[2], b[2]) = (5, 3) is not adjacent to edge between u[2]=3 @(2, 2) and v[2]=2 @(4, 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
17 Correct 7 ms 14328 KB Output is correct
18 Correct 7 ms 14292 KB Output is correct
19 Correct 7 ms 14404 KB Output is correct
20 Correct 600 ms 95748 KB Output is correct
21 Correct 677 ms 84572 KB Output is correct
22 Correct 631 ms 84624 KB Output is correct
23 Correct 519 ms 88672 KB Output is correct
24 Correct 197 ms 31820 KB Output is correct
25 Correct 298 ms 39648 KB Output is correct
26 Correct 262 ms 39704 KB Output is correct
27 Correct 654 ms 94372 KB Output is correct
28 Correct 635 ms 94276 KB Output is correct
29 Correct 700 ms 94300 KB Output is correct
30 Correct 637 ms 94296 KB Output is correct
31 Correct 7 ms 14292 KB Output is correct
32 Correct 33 ms 19440 KB Output is correct
33 Correct 75 ms 23360 KB Output is correct
34 Correct 665 ms 95744 KB Output is correct
35 Correct 14 ms 15700 KB Output is correct
36 Correct 62 ms 20960 KB Output is correct
37 Correct 111 ms 27480 KB Output is correct
38 Correct 212 ms 40876 KB Output is correct
39 Correct 360 ms 49972 KB Output is correct
40 Correct 428 ms 60916 KB Output is correct
41 Correct 620 ms 70264 KB Output is correct
42 Correct 754 ms 79568 KB Output is correct
43 Correct 7 ms 14292 KB Output is correct
44 Correct 7 ms 14292 KB Output is correct
45 Correct 7 ms 14292 KB Output is correct
46 Correct 7 ms 14372 KB Output is correct
47 Correct 7 ms 14404 KB Output is correct
48 Correct 8 ms 14420 KB Output is correct
49 Correct 6 ms 14292 KB Output is correct
50 Correct 7 ms 14400 KB Output is correct
51 Correct 7 ms 14340 KB Output is correct
52 Correct 7 ms 14292 KB Output is correct
53 Correct 7 ms 14320 KB Output is correct
54 Correct 8 ms 14676 KB Output is correct
55 Correct 8 ms 14804 KB Output is correct
56 Correct 339 ms 50844 KB Output is correct
57 Correct 455 ms 68484 KB Output is correct
58 Correct 443 ms 68096 KB Output is correct
59 Correct 7 ms 14292 KB Output is correct
60 Correct 6 ms 14404 KB Output is correct
61 Correct 7 ms 14400 KB Output is correct
62 Correct 595 ms 101152 KB Output is correct
63 Correct 616 ms 101284 KB Output is correct
64 Correct 617 ms 101820 KB Output is correct
65 Correct 9 ms 14932 KB Output is correct
66 Correct 12 ms 15444 KB Output is correct
67 Correct 267 ms 48880 KB Output is correct
68 Correct 483 ms 68284 KB Output is correct
69 Correct 796 ms 83956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
17 Correct 625 ms 104600 KB Output is correct
18 Correct 662 ms 101132 KB Output is correct
19 Correct 766 ms 95236 KB Output is correct
20 Correct 925 ms 88444 KB Output is correct
21 Correct 712 ms 85364 KB Output is correct
22 Correct 7 ms 14400 KB Output is correct
23 Correct 85 ms 25976 KB Output is correct
24 Correct 27 ms 17256 KB Output is correct
25 Correct 87 ms 23824 KB Output is correct
26 Correct 182 ms 30988 KB Output is correct
27 Correct 374 ms 51488 KB Output is correct
28 Correct 472 ms 62048 KB Output is correct
29 Correct 543 ms 71420 KB Output is correct
30 Correct 663 ms 79720 KB Output is correct
31 Correct 814 ms 88648 KB Output is correct
32 Correct 797 ms 96176 KB Output is correct
33 Correct 607 ms 103848 KB Output is correct
34 Correct 10 ms 15080 KB Output is correct
35 Correct 13 ms 15680 KB Output is correct
36 Correct 324 ms 51352 KB Output is correct
37 Correct 508 ms 71452 KB Output is correct
38 Correct 782 ms 89788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14400 KB Output is correct
2 Correct 7 ms 14400 KB Output is correct
3 Correct 8 ms 14308 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14408 KB Output is correct
6 Correct 7 ms 14292 KB Output is correct
7 Correct 7 ms 14292 KB Output is correct
8 Correct 7 ms 14292 KB Output is correct
9 Correct 248 ms 58628 KB Output is correct
10 Correct 20 ms 18956 KB Output is correct
11 Correct 94 ms 38248 KB Output is correct
12 Correct 27 ms 21072 KB Output is correct
13 Correct 30 ms 21628 KB Output is correct
14 Correct 8 ms 14420 KB Output is correct
15 Correct 8 ms 14676 KB Output is correct
16 Correct 262 ms 56912 KB Output is correct
17 Incorrect 7 ms 14404 KB Tree (a[2], b[2]) = (5, 3) is not adjacent to edge between u[2]=3 @(2, 2) and v[2]=2 @(4, 2)
18 Halted 0 ms 0 KB -