답안 #742913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742913 2023-05-17T06:03:41 Z t6twotwo 분수 공원 (IOI21_parks) C++17
15 / 100
148 ms 22376 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
struct dsu {
	int n;
	vector<int> p, s;
	dsu(int m) : n(m), p(n), s(n, 1) {
		iota(p.begin(), p.end(), 0);
	}
	int find(int x) {
		return x == p[x] ? x : p[x] = find(p[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return s[find(x)];
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		if (s[x] > s[y]) {
			swap(x, y);
		}
		s[y] += s[x];
		p[x] = y;
	}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
	int n = x.size();
	int MX = *max_element(x.begin(), x.end());
	if (MX == 2) {
		int mn = *min_element(y.begin(), y.end());
		int mx = *max_element(y.begin(), y.end());
		if (mx - mn != (n - 1) * 2) {
			return 0;
		}
		vector<int> p(n);
		iota(p.begin(), p.end(), 0);
		sort(p.begin(), p.end(), [&](int i, int j) {
			return y[i] < y[j];
		});
		vector<int> u(n - 1), v(n - 1), a(n - 1), b(n - 1);
		for (int i = 0; i < n - 1; i++) {
			u[i] = p[i];
			v[i] = p[i + 1];
			a[i] = 3;
			b[i] = y[p[i]] + 1;
		}
		build(u, v, a, b);
		return 1;
	}
	if (MX == 4) {
		vector<array<int, 2>> a, b;
		for (int i = 0; i < n; i++) {
			if (x[i] == 2) {
				a.push_back({y[i], i});
			} else {
				b.push_back({y[i], i});
			}
		}
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		int s = a.size();
		int t = b.size();
		dsu uf(n);
		vector<int> A, B, C, D;
		for (int i = 0, j = 0; i < s; i++) {
			while (j < t && b[j][0] < a[i][0]) {
				j++;
			}
			if (j < t && a[i][0] == b[j][0]) {
				A.push_back(a[i][1]);
				B.push_back(b[j][1]);
				C.push_back(3);
				D.push_back(a[i][0] + 1);
				uf.unite(a[i][1], b[j][1]);
			}
		}
		for (int i = 0; i + 1 < s; i++) {
			if (a[i][0] + 2 == a[i + 1][0]) {
				A.push_back(a[i][1]);
				B.push_back(a[i + 1][1]);
				C.push_back(1);
				D.push_back(a[i][0] + 1);
				uf.unite(a[i][1], a[i + 1][1]);
			}
		}
		for (int i = 0; i + 1 < t; i++) {
			if (b[i][0] + 2 == b[i + 1][0]) {
				A.push_back(b[i][1]);
				B.push_back(b[i + 1][1]);
				C.push_back(5);
				D.push_back(b[i][0] + 1);
				uf.unite(b[i][1], b[i + 1][1]);
			}
		}
		if (uf.size(0) != n) {
			return 0;
		}
		build(A, B, C, D);
		return 1;
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 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 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 148 ms 20744 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 60 ms 9312 KB Output is correct
29 Correct 92 ms 13596 KB Output is correct
30 Correct 121 ms 18168 KB Output is correct
31 Correct 144 ms 22376 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 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 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 1 ms 212 KB Output is correct
43 Correct 1 ms 308 KB Output is correct
44 Correct 1 ms 476 KB Output is correct
45 Correct 56 ms 9296 KB Output is correct
46 Correct 82 ms 13900 KB Output is correct
47 Correct 87 ms 13876 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 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 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 148 ms 20744 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 60 ms 9312 KB Output is correct
29 Correct 92 ms 13596 KB Output is correct
30 Correct 121 ms 18168 KB Output is correct
31 Correct 144 ms 22376 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 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 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 1 ms 212 KB Output is correct
43 Correct 1 ms 308 KB Output is correct
44 Correct 1 ms 476 KB Output is correct
45 Correct 56 ms 9296 KB Output is correct
46 Correct 82 ms 13900 KB Output is correct
47 Correct 87 ms 13876 KB Output is correct
48 Incorrect 0 ms 212 KB Solution announced impossible, but it is possible.
49 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 KB Output is correct
17 Incorrect 0 ms 212 KB Solution announced impossible, but it is possible.
18 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 KB Output is correct
17 Incorrect 33 ms 3408 KB Solution announced impossible, but it is possible.
18 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 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 52 ms 6980 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 23 ms 3924 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 6 ms 980 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 55 ms 6856 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 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 148 ms 20744 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 60 ms 9312 KB Output is correct
29 Correct 92 ms 13596 KB Output is correct
30 Correct 121 ms 18168 KB Output is correct
31 Correct 144 ms 22376 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 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 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 1 ms 212 KB Output is correct
43 Correct 1 ms 308 KB Output is correct
44 Correct 1 ms 476 KB Output is correct
45 Correct 56 ms 9296 KB Output is correct
46 Correct 82 ms 13900 KB Output is correct
47 Correct 87 ms 13876 KB Output is correct
48 Incorrect 0 ms 212 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -