Submission #205795

# Submission time Handle Problem Language Result Execution time Memory
205795 2020-02-29T22:33:44 Z ArshiaDadras Amusement Park (JOI17_amusement_park) C++17
45 / 100
55 ms 7420 KB
/* In the name of Allah */
#include<bits/stdc++.h>
#include<Joi.h>
using namespace std;

const int N = 1e4 + 5, LG = 60;
int n, m, k, a[N], b[N], root[N], h[N], sz[N], par[N], id[N];
vector<int> ed[N], adj[N];
bitset<N> mark;

void dfs_tree(int u) {
	mark.set(u);
	vector<int> help;
	for (auto v: ed[u])
		if (!mark[v]) {
			help.push_back(v);
			dfs_tree(v), par[v] = u;
		}
	adj[u] = help;
}

void change(int u) {
	for (auto v: adj[u])
		if (!~root[v]) {
			root[v] = root[u];
			change(v);
		}
}

void go(int u) {
	id[u] = sz[root[u]]++;
	for (auto v: adj[u])
		if (k + sz[root[u]] < LG)
			go(v);
}

void go_big(int u) {
	for (sz[u] = 0; true; u = adj[u][0]) {
		id[u] = sz[root[u]]++;
		if (adj[u].empty())
			break;
		k = sz[adj[u][0]];
		for (auto v: adj[u])
			if (v ^ adj[u][0] && k + sz[root[u]] < LG)
				go(v);
	}
}

bool build(int u) {
	vector<int> help;
	sz[u] = 1, h[u] = 0;
	for (auto v: adj[u])
		if (!build(v)) {
			sz[u] += sz[v];
			help.push_back(v);
			h[u] = max(h[u], h[v] + 1);
		}
	sort(help.begin(), help.end(), [] (int u, int v) {
		return h[u] > h[v];
	});
	adj[u] = help;
	if (sz[u] < LG)
		return false;
	change(root[u] = u);
	return go_big(u), true;
}

bool make_root(int u) {
	memset(root, -1, sizeof root);
	memset(id, -1, sizeof id);
	mark.reset(), dfs_tree(u);
	return build(u);
}
void build_tree() {
	if (!make_root(0))
		for (int u = 0; u < n; u++)
			if (~root[u] && !~root[par[u]]) {
				make_root(u);
				break;
			}
}

void Joi(int N, int M, int A[], int B[], long long X, int T) {
	n = N, m = M;
	for (int u = 0; u < n; u++)
		ed[u].clear();
	for (int i = 0; i < m; i++) {
		ed[a[i] = A[i]].push_back(B[i]);
		ed[b[i] = B[i]].push_back(A[i]);
	}
	build_tree();
	for (int u = 0; u < n; u++)
		MessageBoard(u, ~id[u]? X >> id[u] & 1: 0);
}
/* In the name of Allah */
#include<bits/stdc++.h>
#include<Ioi.h>
using namespace std;

const int N = 1e4 + 5, LG = 60;
int n, m, k, a[N], b[N], root[N], h[N], sz[N], par[N], id[N];
vector<int> ed[N], adj[N], path[N];
bitset<N> mark;

void dfs_tree(int u) {
	mark.set(u);
	vector<int> help;
	for (auto v: ed[u])
		if (!mark[v]) {
			help.push_back(v);
			dfs_tree(v), par[v] = u;
		}
	adj[u] = help;
}

void change(int u) {
	for (auto v: adj[u])
		if (!~root[v]) {
			root[v] = root[u];
			change(v);
		}
}

void go(int u) {
	id[u] = sz[root[u]]++;
	path[root[u]].push_back(u);
	for (auto v: adj[u])
		if (k + sz[root[u]] < LG)
			go(v), path[root[u]].push_back(u);
}

void go_big(int u) {
	for (sz[u] = 0; true; u = adj[u][0]) {
		path[root[u]].push_back(u);
		id[u] = sz[root[u]]++;
		if (adj[u].empty())
			break;
		k = sz[adj[u][0]];
		for (auto v: adj[u])
			if (v ^ adj[u][0] && k + sz[root[u]] < LG)
				go(v), path[root[u]].push_back(u);
	}
}

bool build(int u) {
	vector<int> help;
	sz[u] = 1, h[u] = 0;
	for (auto v: adj[u])
		if (!build(v)) {
			sz[u] += sz[v];
			help.push_back(v);
			h[u] = max(h[u], h[v] + 1);
		}
	sort(help.begin(), help.end(), [] (int u, int v) {
		return h[u] > h[v];
	});
	adj[u] = help;
	if (sz[u] < LG)
		return false;
	change(root[u] = u);
	return go_big(u), true;
}

bool make_root(int u) {
	for (int v = 0; v < n; v++)
		path[v].clear();
	memset(root, -1, sizeof root);
	memset(id, -1, sizeof id);
	mark.reset(), dfs_tree(u);
	return build(u);
}

void build_tree() {
	if (!make_root(0))
		for (int u = 0; u < n; u++)
			if (~root[u] && !~root[par[u]]) {
				make_root(u);
				break;
			}
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	n = N, m = M;
	for (int u = 0; u < n; u++)
		ed[u].clear();
	for (int i = 0; i < m; i++) {
		ed[a[i] = A[i]].push_back(B[i]);
		ed[b[i] = B[i]].push_back(A[i]);
	}
	build_tree();
	while (P ^ root[P])
		V = Move(P = par[P]);
	long long answer = V;
	for (auto u: path[P]) {
		if (P ^ u)
			V = Move(P = u);
		answer |= 1LL * V << id[P];
	}
	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2232 KB Output is correct
2 Correct 10 ms 2168 KB Output is correct
3 Correct 10 ms 2204 KB Output is correct
4 Correct 10 ms 2220 KB Output is correct
5 Correct 11 ms 2220 KB Output is correct
6 Correct 10 ms 2076 KB Output is correct
7 Correct 11 ms 2172 KB Output is correct
8 Correct 10 ms 2044 KB Output is correct
9 Correct 12 ms 2208 KB Output is correct
10 Correct 10 ms 2216 KB Output is correct
11 Correct 14 ms 2704 KB Output is correct
12 Correct 10 ms 2220 KB Output is correct
13 Correct 11 ms 2048 KB Output is correct
14 Correct 10 ms 2176 KB Output is correct
15 Correct 10 ms 2176 KB Output is correct
16 Correct 10 ms 2052 KB Output is correct
17 Correct 10 ms 2192 KB Output is correct
18 Correct 12 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 5600 KB Output is correct
2 Correct 43 ms 6168 KB Output is correct
3 Correct 43 ms 5916 KB Output is correct
4 Correct 34 ms 4572 KB Output is correct
5 Correct 35 ms 6104 KB Output is correct
6 Correct 36 ms 5656 KB Output is correct
7 Correct 37 ms 5652 KB Output is correct
8 Correct 31 ms 5604 KB Output is correct
9 Correct 38 ms 5788 KB Output is correct
10 Correct 27 ms 4544 KB Output is correct
11 Correct 28 ms 4556 KB Output is correct
12 Correct 30 ms 4400 KB Output is correct
13 Correct 34 ms 4388 KB Output is correct
14 Correct 31 ms 4608 KB Output is correct
15 Correct 32 ms 4848 KB Output is correct
16 Correct 35 ms 4864 KB Output is correct
17 Correct 34 ms 4508 KB Output is correct
18 Correct 35 ms 4532 KB Output is correct
19 Correct 34 ms 4508 KB Output is correct
20 Correct 30 ms 5920 KB Output is correct
21 Correct 28 ms 5788 KB Output is correct
22 Correct 37 ms 5500 KB Output is correct
23 Correct 36 ms 5592 KB Output is correct
24 Correct 35 ms 5308 KB Output is correct
25 Correct 35 ms 5648 KB Output is correct
26 Correct 35 ms 5672 KB Output is correct
27 Correct 33 ms 5672 KB Output is correct
28 Correct 30 ms 5608 KB Output is correct
29 Correct 31 ms 5252 KB Output is correct
30 Correct 33 ms 5384 KB Output is correct
31 Correct 10 ms 2188 KB Output is correct
32 Correct 11 ms 2216 KB Output is correct
33 Correct 10 ms 2204 KB Output is correct
34 Correct 10 ms 2208 KB Output is correct
35 Correct 10 ms 2220 KB Output is correct
36 Correct 11 ms 2192 KB Output is correct
37 Correct 10 ms 2220 KB Output is correct
38 Correct 10 ms 2224 KB Output is correct
39 Correct 10 ms 2228 KB Output is correct
40 Correct 11 ms 2220 KB Output is correct
41 Correct 10 ms 2188 KB Output is correct
42 Correct 10 ms 2228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2212 KB Output is correct
2 Correct 10 ms 2164 KB Output is correct
3 Correct 10 ms 2216 KB Output is correct
4 Correct 14 ms 2836 KB Output is correct
5 Correct 14 ms 3092 KB Output is correct
6 Correct 13 ms 2848 KB Output is correct
7 Correct 13 ms 3000 KB Output is correct
8 Correct 14 ms 3000 KB Output is correct
9 Correct 33 ms 7420 KB Output is correct
10 Correct 31 ms 7420 KB Output is correct
11 Correct 31 ms 7360 KB Output is correct
12 Correct 10 ms 2216 KB Output is correct
13 Correct 10 ms 2220 KB Output is correct
14 Correct 10 ms 2228 KB Output is correct
15 Correct 10 ms 2220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5736 KB Output is correct
2 Correct 46 ms 5668 KB Output is correct
3 Incorrect 34 ms 4224 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 5596 KB Output is correct
2 Correct 44 ms 5996 KB Output is correct
3 Correct 43 ms 5624 KB Output is correct
4 Correct 33 ms 4324 KB Output is correct
5 Correct 31 ms 6388 KB Output is correct
6 Correct 35 ms 5428 KB Output is correct
7 Correct 36 ms 5220 KB Output is correct
8 Correct 35 ms 5652 KB Output is correct
9 Correct 30 ms 5064 KB Output is correct
10 Correct 27 ms 4620 KB Output is correct
11 Correct 27 ms 4400 KB Output is correct
12 Correct 31 ms 4384 KB Output is correct
13 Correct 27 ms 4396 KB Output is correct
14 Correct 32 ms 4364 KB Output is correct
15 Correct 33 ms 4540 KB Output is correct
16 Correct 32 ms 4412 KB Output is correct
17 Correct 35 ms 4308 KB Output is correct
18 Correct 33 ms 4284 KB Output is correct
19 Correct 33 ms 4296 KB Output is correct
20 Correct 28 ms 5952 KB Output is correct
21 Correct 30 ms 5564 KB Output is correct
22 Correct 33 ms 5384 KB Output is correct
23 Correct 28 ms 5108 KB Output is correct
24 Correct 33 ms 5212 KB Output is correct
25 Correct 35 ms 5420 KB Output is correct
26 Correct 33 ms 5128 KB Output is correct
27 Correct 33 ms 5608 KB Output is correct
28 Correct 55 ms 5824 KB Output is correct
29 Correct 33 ms 5292 KB Output is correct
30 Correct 34 ms 5300 KB Output is correct
31 Correct 10 ms 2164 KB Output is correct
32 Correct 10 ms 2344 KB Output is correct
33 Correct 10 ms 2200 KB Output is correct
34 Correct 10 ms 2196 KB Output is correct
35 Correct 10 ms 2212 KB Output is correct
36 Correct 10 ms 2164 KB Output is correct
37 Correct 10 ms 2220 KB Output is correct
38 Correct 10 ms 2216 KB Output is correct
39 Correct 11 ms 2220 KB Output is correct
40 Correct 10 ms 2196 KB Output is correct
41 Correct 10 ms 2200 KB Output is correct
42 Correct 10 ms 2228 KB Output is correct