답안 #628108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628108 2022-08-13T05:22:33 Z MilosMilutinovic 분수 공원 (IOI21_parks) C++17
5 / 100
427 ms 32372 KB
#include "parks.h"
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int n, x[200005], y[200005];
PII ord[200005];
int rt[200005];
int root(int x)
{
	return rt[x] == x ? x : rt[x] = root(rt[x]);
}
map<PII, int> idx;
vector<int> u, v, a, b;
void add(int i, int j)
{
	u.push_back(i);
	v.push_back(j);
	rt[root(i)] = root(j);
	if(x[i] == x[j]) {
		if((x[i] + y[i]) % 2 == 1) a.push_back(x[i] - 1);
		else a.push_back(x[i] + 1);
		b.push_back((y[i] + y[j]) / 2);
	} else {
		a.push_back((x[i] + x[j]) / 2);
		if((x[i] + y[i]) % 2 == 1) b.push_back(y[i] + 1);
		else b.push_back(y[i] - 1);
	}
}
int construct_roads(vector<int> X, vector<int> Y)
{
	n = (int) X.size();
	rep(i, n) {
		x[i] = X[i];
		y[i] = Y[i];
		rt[i] = i;
		idx[{x[i], y[i]}] = i;
	}

    rep(i, n) ord[i] = MP(x[i] + y[i], i);
	sort(ord, ord + n);
	reverse(ord, ord + n);
	rep(id, n) {
		int i = ord[id].second;
		int id0 = (idx.count(MP(x[i] + 2, y[i])) ? idx[MP(x[i] + 2, y[i])] : -1);
		int id1 = (idx.count(MP(x[i], y[i] + 2)) ? idx[MP(x[i], y[i] + 2)] : -1);
		if(id0 == -1 && id1 == -1) continue;
		if(id0 != -1 && id1 == -1) add(i, id0);
		if(id0 == -1 && id1 != -1) add(i, id1);
		if(id0 != -1 && id1 != -1) {
			if(root(id0) != root(id1)) {
				add(i, id0); add(i, id1);
			} else {
				if(ord[id].first % 2 == 1) add(i, id1);
				else add(i, id0);
			}
		}
	}

	if((int) u.size() != n - 1) return 0;

	build(u, v, a, b);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 284 ms 31132 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 444 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 92 ms 12572 KB Output is correct
29 Incorrect 170 ms 18868 KB Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 284 ms 31132 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 444 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 92 ms 12572 KB Output is correct
29 Incorrect 170 ms 18868 KB Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 300 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 427 ms 32372 KB Output is correct
21 Incorrect 293 ms 31936 KB Tree @(99999, 100003) appears more than once: for edges on positions 1 and 2
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
17 Incorrect 300 ms 31448 KB Tree @(3, 100001) appears more than once: for edges on positions 99999 and 100000
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 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 110 ms 15672 KB Output is correct
10 Correct 11 ms 2004 KB Output is correct
11 Correct 57 ms 8580 KB Output is correct
12 Correct 14 ms 2900 KB Output is correct
13 Correct 31 ms 5832 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 111 ms 15772 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 284 ms 31132 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 444 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 92 ms 12572 KB Output is correct
29 Incorrect 170 ms 18868 KB Tree @(3, 80003) appears more than once: for edges on positions 119996 and 119997
30 Halted 0 ms 0 KB -