답안 #205704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205704 2020-02-29T14:16:40 Z ArshiaDadras Amusement Park (JOI17_amusement_park) C++14
10 / 100
3000 ms 7008 KB
/* In the name of Allah */
#include<bits/stdc++.h>
#include<Joi.h>
using namespace std;

const int N = 1e4 + 5;
int n, m, k, a[N], b[N], root[N], down[N], sz[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]) {
			dfs_tree(v);
			help.push_back(v);
		}
	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]] < 60)
			go(v);
}

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

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

void build_tree(int u) {
	memset(root, -1, sizeof root);
	memset(id, -1, sizeof id);
	mark.reset(), dfs_tree(u);
	if (!build(u))
		for (int i = 0; i < m; i++) {
			if (~root[a[i]])
				swap(a[i], b[i]);
			if (!~root[a[i]] && ~root[b[i]])
				build_tree(b[i]);
		}
}

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(0);
	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;
int n, m, k, a[N], b[N], root[N], down[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]] < 60)
			go(v), path[root[u]].push_back(u);
}

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

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

void build_tree(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);
	if (!build(u))
		for (int i = 0; i < m; i++) {
			if (~root[a[i]])
				swap(a[i], b[i]);
			if (!~root[a[i]] && ~root[b[i]])
				build_tree(b[i]);
		}
}

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(0);
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2220 KB Output is correct
2 Correct 10 ms 2204 KB Output is correct
3 Correct 10 ms 2200 KB Output is correct
4 Correct 10 ms 2172 KB Output is correct
5 Correct 10 ms 2468 KB Output is correct
6 Correct 11 ms 2036 KB Output is correct
7 Correct 10 ms 2192 KB Output is correct
8 Correct 10 ms 2204 KB Output is correct
9 Correct 11 ms 2340 KB Output is correct
10 Correct 10 ms 2048 KB Output is correct
11 Execution timed out 3081 ms 4244 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3081 ms 2560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2228 KB Output is correct
2 Correct 11 ms 2208 KB Output is correct
3 Correct 10 ms 2188 KB Output is correct
4 Correct 19 ms 3088 KB Output is correct
5 Correct 14 ms 3196 KB Output is correct
6 Correct 14 ms 3052 KB Output is correct
7 Correct 14 ms 3048 KB Output is correct
8 Correct 14 ms 3056 KB Output is correct
9 Correct 31 ms 7008 KB Output is correct
10 Correct 31 ms 6972 KB Output is correct
11 Correct 31 ms 6972 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 2200 KB Output is correct
15 Correct 12 ms 2228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3079 ms 2628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3080 ms 2588 KB Time limit exceeded
2 Halted 0 ms 0 KB -