답안 #102738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102738 2019-03-27T11:07:54 Z Minnakhmetov Amusement Park (JOI17_amusement_park) C++14
0 / 100
546 ms 191128 KB
#include "Joi.h"

#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

static const int N = 1e4 + 5, D = 60;
static vector<int> g[N];
static int num[N];

static struct Tree {
	vector<int> t[D];
	int id_to_node[D];
	map<int, int> node_to_id;

	Tree() {
		fill(id_to_node, id_to_node + D, -1);
	}

	void addNode(int node) {
		for (int i = 0; i < D; i++) {
			if (id_to_node[i] == -1) {
				id_to_node[i] = node;
				node_to_id[node] = i;
				break;
			}
		}
	}
	void addEdge(int x, int y) {
		x = node_to_id[x];
		y = node_to_id[y];
		t[x].push_back(y);
		t[y].push_back(x);
	}

	void delNode(int id) {
		for (int to : t[id]) {
			t[to].erase(find(all(t[to]), id));
		}
		t[id].clear();
		node_to_id.erase(id_to_node[id]);
		id_to_node[id] = -1;
	}

	int popLeafNotEqualTo(int node) {
		int id = -1;
		for (int i = 0; i < D; i++) {
			if (id_to_node[i] != -1 &&
				id_to_node[i] != node) {
				id = i;
				break;
			}
		}
		int deletedNode = id_to_node[id];
		delNode(id);
		return deletedNode;
	}

	int getNodeCount() {
		return node_to_id.size();
	}

} tr[N];

static void dfs(int node, int anc, Tree &t) {
	num[node] = t.getNodeCount();
	t.addNode(node);
	if (anc != -1)
		t.addEdge(node, anc);
	if (t.getNodeCount() == 60)
		return;
	for (int to : g[node]) {
		if (num[to] == -1) {
			dfs(to, node, t);
			if (t.getNodeCount() == 60)
				return;
		}
	}
}

static void deep(int node, int anc, Tree t) {
	num[node] = num[t.popLeafNotEqualTo(anc)];
	t.addNode(node);
	t.addEdge(node, anc);
	tr[node] = t;

	for (int to : g[node]) {
		if (num[to] == -1) {
			deep(to, node, t);
		}
	}
}

void Joi(int n, int m, int A[], int B[], long long x, int t) {
	for (int i = 0; i < m; i++) {
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}

	fill(num, num + n, -1);

	Tree fir;
	dfs(0, -1, fir);

	for (int i = 0; i < n; i++) {
		if (num[i] != -1)
			tr[i] = fir;
	}

	for (int i = 0; i < n; i++) {
		if (num[i] != -1) {
			for (int to : g[i]) {
				if (num[to] == -1) {
					deep(to, i, fir);
				}
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		MessageBoard(i, (x >> num[i]) & 1);
	}
}
#include "Ioi.h"

#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

static const int N = 1e4 + 5, D = 60;
static vector<int> g[N];
static int num[N];

struct Tree {
	vector<int> t[D];
	int id_to_node[D];
	map<int, int> node_to_id;

	Tree() {
		fill(id_to_node, id_to_node + D, -1);
	}

	void addNode(int node) {
		for (int i = 0; i < D; i++) {
			if (id_to_node[i] == -1) {
				id_to_node[i] = node;
				node_to_id[node] = i;
				break;
			}
		}
	}
	void addEdge(int x, int y) {
		x = node_to_id[x];
		y = node_to_id[y];
		t[x].push_back(y);
		t[y].push_back(x);
	}

	void delNode(int id) {
		for (int to : t[id]) {
			t[to].erase(find(all(t[to]), id));
		}
		t[id].clear();
		node_to_id.erase(id_to_node[id]);
		id_to_node[id] = -1;
	}

	int popLeafNotEqualTo(int node) {
		int id = -1;
		for (int i = 0; i < D; i++) {
			if (id_to_node[i] != -1 &&
				id_to_node[i] != node) {
				id = i;
				break;
			}
		}
		int deletedNode = id_to_node[id];
		delNode(id);
		return deletedNode;
	}

	int getNodeCount() {
		return node_to_id.size();
	}

} tr[N];

void dfs(int node, int anc, Tree &t) {
	num[node] = t.getNodeCount();
	t.addNode(node);
	if (anc != -1)
		t.addEdge(node, anc);
	if (t.getNodeCount() == 60)
		return;
	for (int to : g[node]) {
		if (num[to] == -1) {
			dfs(to, node, t);
			if (t.getNodeCount() == 60)
				return;
		}
	}
}

void deep(int node, int anc, Tree t) {
	num[node] = num[t.popLeafNotEqualTo(anc)];
	t.addNode(node);
	t.addEdge(node, anc);
	tr[node] = t;

	for (int to : g[node]) {
		if (num[to] == -1) {
			deep(to, node, t);
		}
	}
}

ll ans = 0;
static bool used[D];

void walk(int node, int anc, Tree &t) {
	used[node] = 1;
	for (int to : t.t[node]) {
		if (!used[to]) {
			ans |= (ll)Move(t.id_to_node[to]) << num[t.id_to_node[to]];
			walk(to, node, t);
		}
	}
	if (anc != -1)
		Move(t.id_to_node[anc]);
}

long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) {
	for (int i = 0; i < m; i++) {
		g[A[i]].push_back(B[i]);
		g[B[i]].push_back(A[i]);
	}

	fill(num, num + n, -1);

	Tree fir;
	dfs(0, -1, fir);

	for (int i = 0; i < n; i++) {
		if (num[i] != -1)
			tr[i] = fir;
	}

	for (int i = 0; i < n; i++) {
		if (num[i] != -1) {
			for (int to : g[i]) {
				if (num[to] == -1) {
					deep(to, i, fir);
				}
			}
		}
	}

	ans |= (ll)V << num[P];

	walk(tr[P].node_to_id[P], -1, tr[P]);

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 35872 KB Output is correct
2 Correct 47 ms 36592 KB Output is correct
3 Incorrect 50 ms 38172 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 505 ms 191044 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 36352 KB Output is correct
2 Correct 37 ms 36436 KB Output is correct
3 Incorrect 39 ms 36352 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 546 ms 190044 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 510 ms 191128 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -