답안 #742908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742908 2023-05-17T05:59:42 Z t6twotwo 분수 공원 (IOI21_parks) C++17
5 / 100
162 ms 22464 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[i][1]);
				C.push_back(3);
				D.push_back(a[i][0] + 1);
				uf.unite(a[i][1], b[i][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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 162 ms 22464 KB Output is correct
24 Incorrect 0 ms 212 KB Pair u[2]=6 @(2, 183576) and v[2]=5 @(4, 183574) does not form a valid edge (distance != 2)
25 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 162 ms 22464 KB Output is correct
24 Incorrect 0 ms 212 KB Pair u[2]=6 @(2, 183576) and v[2]=5 @(4, 183574) does not form a valid edge (distance != 2)
25 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 KB Output is correct
17 Incorrect 36 ms 3416 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 58 ms 6840 KB Output is correct
10 Correct 5 ms 1012 KB Output is correct
11 Correct 27 ms 3796 KB Output is correct
12 Correct 8 ms 1560 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 57 ms 6848 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 2 ms 212 KB Output is correct
23 Correct 162 ms 22464 KB Output is correct
24 Incorrect 0 ms 212 KB Pair u[2]=6 @(2, 183576) and v[2]=5 @(4, 183574) does not form a valid edge (distance != 2)
25 Halted 0 ms 0 KB -