Submission #146247

# Submission time Handle Problem Language Result Execution time Memory
146247 2019-08-23T04:48:19 Z jwvg0425 Split the Attractions (IOI19_split) C++17
40 / 100
225 ms 22328 KB
#include "split.h"
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

vector<int> edge[100005];
vector<int> treeEdge[100005];
bool visited[100005];
int cent;
int val[100005];
int treeSize[100005];
int parent[100005];

void dfs(int root)
{
	visited[root] = true;

	for (auto& e : edge[root])
	{
		if (visited[e])
			continue;

		treeEdge[root].push_back(e);
		treeEdge[e].push_back(root);

		dfs(e);
	}
}

int findCent(int root, int n)
{
	treeSize[root] = 1;

	bool isCent = true;

	for (auto& e : treeEdge[root])
	{
		if (e == parent[root])
			continue;

		parent[e] = root;
		int c = findCent(e, n);

		if (c != -1)
			return c;

		treeSize[root] += treeSize[e];

		isCent = isCent && (treeSize[e] < (n + 1) / 2);
	}

	if (isCent && treeSize[root] >= (n + 1) / 2)
		return root;

	return -1;
}

int comp(int root)
{
	// cent 방향 안 가면서 크기 계산
	int res = 1;
	visited[root] = true;

	for (auto& e : edge[root])
	{
		if (visited[e] || e == cent)
			continue;

		res += comp(e);
	}

	return res;
}

void mark(int root, int v, int& c)
{
	if (c == 0)
		return;

	val[root] = v;
	c--;

	for (auto& e : edge[root])
	{
		if (val[e] != 0)
			continue;

		mark(e, v, c);
	}
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) 
{
	vector<ii> v = { { a, 1 }, { b, 2 }, { c, 3 } };

	for (int i = 0; i < p.size(); i++)
	{
		edge[p[i]].push_back(q[i]);
		edge[q[i]].push_back(p[i]);
	}

	dfs(0);

	sort(all(v));

	cent = findCent(0, n);

	// centroid 제외한 그래프에서 a이상의 크기인 트리가 있는지 확인, 있으면 go
	memset(visited, false, sizeof(visited));

	for (auto& e : edge[cent])
	{
		int sz = comp(e);

		if (sz < v[0].xx)
			continue;

		val[cent] = v[1].yy;
		mark(e, v[0].yy, v[0].xx);
		mark(cent, v[1].yy, v[1].xx);

		assert(v[0].xx == 0);
		assert(v[1].xx == 0);

		for (int i = 0; i < n; i++)
			if (val[i] == 0)
				val[i] = v[2].yy;

		break;
	}

	vector<int> result(n);
	for (int i = 0; i < n; i++)
		result[i] = val[i];

	return result;
}

Compilation message

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:118:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p.size(); i++)
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 5112 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 6 ms 5240 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Correct 6 ms 5112 KB ok, correct split
7 Correct 147 ms 22008 KB ok, correct split
8 Correct 142 ms 19704 KB ok, correct split
9 Correct 157 ms 19032 KB ok, correct split
10 Correct 172 ms 22308 KB ok, correct split
11 Correct 225 ms 22328 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 5112 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 180 ms 19156 KB ok, correct split
5 Correct 125 ms 14804 KB ok, correct split
6 Correct 150 ms 22264 KB ok, correct split
7 Correct 155 ms 19576 KB ok, correct split
8 Correct 182 ms 16504 KB ok, correct split
9 Correct 147 ms 14584 KB ok, correct split
10 Correct 96 ms 15344 KB ok, correct split
11 Correct 122 ms 15312 KB ok, correct split
12 Correct 109 ms 15328 KB ok, correct split
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB ok, correct split
2 Correct 131 ms 14684 KB ok, correct split
3 Correct 49 ms 9080 KB ok, correct split
4 Correct 6 ms 5112 KB ok, correct split
5 Correct 146 ms 17092 KB ok, correct split
6 Correct 158 ms 16888 KB ok, correct split
7 Correct 166 ms 16764 KB ok, correct split
8 Correct 166 ms 18180 KB ok, correct split
9 Correct 146 ms 16504 KB ok, correct split
10 Correct 40 ms 8312 KB ok, no valid answer
11 Correct 56 ms 9720 KB ok, no valid answer
12 Correct 115 ms 14688 KB ok, no valid answer
13 Correct 132 ms 14440 KB ok, no valid answer
14 Correct 98 ms 14932 KB ok, no valid answer
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 5112 KB ok, no valid answer
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 7 ms 5112 KB ok, correct split
5 Correct 7 ms 5112 KB ok, correct split
6 Correct 8 ms 5112 KB ok, correct split
7 Runtime error 14 ms 10232 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB ok, correct split
2 Correct 6 ms 5112 KB ok, correct split
3 Correct 6 ms 5112 KB ok, correct split
4 Correct 6 ms 5240 KB ok, correct split
5 Correct 6 ms 5112 KB ok, correct split
6 Correct 6 ms 5112 KB ok, correct split
7 Correct 147 ms 22008 KB ok, correct split
8 Correct 142 ms 19704 KB ok, correct split
9 Correct 157 ms 19032 KB ok, correct split
10 Correct 172 ms 22308 KB ok, correct split
11 Correct 225 ms 22328 KB ok, correct split
12 Correct 6 ms 5112 KB ok, correct split
13 Correct 6 ms 5112 KB ok, correct split
14 Correct 6 ms 5112 KB ok, correct split
15 Correct 180 ms 19156 KB ok, correct split
16 Correct 125 ms 14804 KB ok, correct split
17 Correct 150 ms 22264 KB ok, correct split
18 Correct 155 ms 19576 KB ok, correct split
19 Correct 182 ms 16504 KB ok, correct split
20 Correct 147 ms 14584 KB ok, correct split
21 Correct 96 ms 15344 KB ok, correct split
22 Correct 122 ms 15312 KB ok, correct split
23 Correct 109 ms 15328 KB ok, correct split
24 Correct 6 ms 5240 KB ok, correct split
25 Correct 131 ms 14684 KB ok, correct split
26 Correct 49 ms 9080 KB ok, correct split
27 Correct 6 ms 5112 KB ok, correct split
28 Correct 146 ms 17092 KB ok, correct split
29 Correct 158 ms 16888 KB ok, correct split
30 Correct 166 ms 16764 KB ok, correct split
31 Correct 166 ms 18180 KB ok, correct split
32 Correct 146 ms 16504 KB ok, correct split
33 Correct 40 ms 8312 KB ok, no valid answer
34 Correct 56 ms 9720 KB ok, no valid answer
35 Correct 115 ms 14688 KB ok, no valid answer
36 Correct 132 ms 14440 KB ok, no valid answer
37 Correct 98 ms 14932 KB ok, no valid answer
38 Correct 6 ms 5112 KB ok, correct split
39 Correct 6 ms 5112 KB ok, no valid answer
40 Correct 6 ms 5112 KB ok, correct split
41 Correct 7 ms 5112 KB ok, correct split
42 Correct 7 ms 5112 KB ok, correct split
43 Correct 8 ms 5112 KB ok, correct split
44 Runtime error 14 ms 10232 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Halted 0 ms 0 KB -