답안 #99647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99647 2019-03-06T03:18:57 Z square1001 Amusement Park (JOI17_amusement_park) C++14
100 / 100
280 ms 26708 KB
#include "Joi.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
const int bits = 60;
struct edge {
	int a, b;
	edge() : a(-1), b(-1) {};
	edge(int a_, int b_) : a(a_), b(b_) {};
};
pair<vector<vector<edge> >, vector<int> > generate(int N, vector<vector<int> > G) {
	vector<int> d(N, -1), par(N, -1);
	function<void(int, int)> find_depth = [&](int pos, int pre) {
		d[pos] = (pre == -1 ? 0 : d[pre] + 1);
		par[pos] = pre;
		for(int i : G[pos]) {
			if(i != pre) find_depth(i, pos);
		}
	};
	find_depth(0, -1);
	vector<int> ord(N);
	for(int i = 0; i < N; ++i) ord[i] = i;
	sort(ord.begin(), ord.end(), [&](int i, int j) { return d[i] < d[j]; });
	vector<int> inv(N);
	for(int i = 0; i < N; ++i) inv[ord[i]] = i;
	vector<edge> ini;
	for(int i = 0; i < bits; ++i) {
		for(int j : G[ord[i]]) {
			if(inv[j] < bits && ord[i] < j) {
				ini.push_back(edge(ord[i], j));
			}
		}
	}
	vector<vector<edge> > ans(N);
	vector<int> id(N, -1);
	for(int i = 0; i < bits; ++i) {
		ans[ord[i]] = ini;
		id[ord[i]] = i;
	}
	for(int i = bits; i < N; ++i) {
		unordered_map<int, int> tbl;
		for(edge j : ans[par[ord[i]]]) {
			++tbl[j.a];
			++tbl[j.b];
		}
		int eraser = -1;
		for(pair<int, int> j : tbl) {
			if(j.second == 1 && j.first != par[ord[i]]) {
				eraser = j.first;
			}
		}
		for(edge j : ans[par[ord[i]]]) {
			if(j.a != eraser && j.b != eraser) {
				ans[ord[i]].push_back(j);
			}
		}
		ans[ord[i]].push_back(edge(ord[i], par[ord[i]]));
		id[ord[i]] = id[eraser];
	}
	return make_pair(ans, id);
}
vector<vector<int> > get_spanning_tree(int N, vector<vector<int> > G) {
	vector<vector<int> > ans(N);
	vector<bool> vis(N);
	function<void(int)> dfs = [&](int pos) {
		vis[pos] = true;
		for(int i : G[pos]) {
			if(!vis[i]) {
				ans[pos].push_back(i);
				ans[i].push_back(pos);
				dfs(i);
			}
		}
	};
	dfs(0);
	return ans;
}
void Joi(int N, int M, int A[], int B[], long long X, int T) {
	vector<vector<int> > G(N);
	for(int i = 0; i < M; ++i) {
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	G = get_spanning_tree(N, G);
	pair<vector<vector<edge> >, vector<int> > res = generate(N, G);
	for(int i = 0; i < N; ++i) {
		int val = (X >> res.second[i]) & 1;
		MessageBoard(i, val);
	}
}
#include "Ioi.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
const int bits = 60;
struct edge {
	int a, b;
	edge() : a(-1), b(-1) {};
	edge(int a_, int b_) : a(a_), b(b_) {};
};
pair<vector<vector<edge> >, vector<int> > generate2(int N, vector<vector<int> > G) {
	vector<int> d(N, -1), par(N, -1);
	function<void(int, int)> find_depth = [&](int pos, int pre) {
		d[pos] = (pre == -1 ? 0 : d[pre] + 1);
		par[pos] = pre;
		for(int i : G[pos]) {
			if(i != pre) find_depth(i, pos);
		}
	};
	find_depth(0, -1);
	vector<int> ord(N);
	for(int i = 0; i < N; ++i) ord[i] = i;
	sort(ord.begin(), ord.end(), [&](int i, int j) { return d[i] < d[j]; });
	vector<int> inv(N);
	for(int i = 0; i < N; ++i) inv[ord[i]] = i;
	vector<edge> ini;
	for(int i = 0; i < bits; ++i) {
		for(int j : G[ord[i]]) {
			if(inv[j] < bits && ord[i] < j) {
				ini.push_back(edge(ord[i], j));
			}
		}
	}
	vector<vector<edge> > ans(N);
	vector<int> id(N, -1);
	for(int i = 0; i < bits; ++i) {
		ans[ord[i]] = ini;
		id[ord[i]] = i;
	}
	for(int i = bits; i < N; ++i) {
		unordered_map<int, int> tbl;
		for(edge j : ans[par[ord[i]]]) {
			++tbl[j.a];
			++tbl[j.b];
		}
		int eraser = -1;
		for(pair<int, int> j : tbl) {
			if(j.second == 1 && j.first != par[ord[i]]) {
				eraser = j.first;
			}
		}
		for(edge j : ans[par[ord[i]]]) {
			if(j.a != eraser && j.b != eraser) {
				ans[ord[i]].push_back(j);
			}
		}
		ans[ord[i]].push_back(edge(ord[i], par[ord[i]]));
		id[ord[i]] = id[eraser];
	}
	return make_pair(ans, id);
}
vector<vector<int> > get_spanning_tree2(int N, vector<vector<int> > G) {
	vector<vector<int> > ans(N);
	vector<bool> vis(N);
	function<void(int)> dfs = [&](int pos) {
		vis[pos] = true;
		for(int i : G[pos]) {
			if(!vis[i]) {
				ans[pos].push_back(i);
				ans[i].push_back(pos);
				dfs(i);
			}
		}
	};
	dfs(0);
	return ans;
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	vector<vector<int> > G(N);
	for(int i = 0; i < M; ++i) {
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	G = get_spanning_tree2(N, G);
	pair<vector<vector<edge> >, vector<int> > res = generate2(N, G);
	vector<int> id = res.second;
	vector<edge> subgraph = res.first[P];
	vector<bool> vis(N);
	vector<int> route;
	function<void(int)> dfs = [&](int pos) {
		vis[pos] = true;
		route.push_back(pos);
		for(edge e : subgraph) {
			if(e.a == pos && !vis[e.b]) dfs(e.b);
			if(e.b == pos && !vis[e.a]) dfs(e.a);
			route.push_back(pos);
		}
	};
	dfs(P);
	route.erase(unique(route.begin(), route.end()), route.end());
	long long ans = (long long)(V) << id[P];
	for(int i = 1; i < route.size(); ++i) {
		ans |= (long long)(Move(route[i])) << id[route[i]];
	}
	return ans;
}

Compilation message

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:104:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < route.size(); ++i) {
                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 900 KB Output is correct
2 Correct 7 ms 1028 KB Output is correct
3 Correct 8 ms 1416 KB Output is correct
4 Correct 4 ms 1164 KB Output is correct
5 Correct 6 ms 1076 KB Output is correct
6 Correct 7 ms 1156 KB Output is correct
7 Correct 10 ms 1424 KB Output is correct
8 Correct 7 ms 1416 KB Output is correct
9 Correct 7 ms 1296 KB Output is correct
10 Correct 5 ms 1156 KB Output is correct
11 Correct 10 ms 1456 KB Output is correct
12 Correct 4 ms 900 KB Output is correct
13 Correct 9 ms 1448 KB Output is correct
14 Correct 9 ms 1416 KB Output is correct
15 Correct 10 ms 1428 KB Output is correct
16 Correct 10 ms 1416 KB Output is correct
17 Correct 9 ms 1424 KB Output is correct
18 Correct 12 ms 1544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 26696 KB Output is correct
2 Correct 244 ms 26544 KB Output is correct
3 Correct 239 ms 26472 KB Output is correct
4 Correct 247 ms 24812 KB Output is correct
5 Correct 212 ms 25632 KB Output is correct
6 Correct 226 ms 25448 KB Output is correct
7 Correct 206 ms 25596 KB Output is correct
8 Correct 234 ms 25456 KB Output is correct
9 Correct 206 ms 25540 KB Output is correct
10 Correct 226 ms 25176 KB Output is correct
11 Correct 184 ms 25008 KB Output is correct
12 Correct 190 ms 22680 KB Output is correct
13 Correct 205 ms 22776 KB Output is correct
14 Correct 187 ms 23784 KB Output is correct
15 Correct 204 ms 24976 KB Output is correct
16 Correct 224 ms 24912 KB Output is correct
17 Correct 187 ms 25056 KB Output is correct
18 Correct 190 ms 25028 KB Output is correct
19 Correct 190 ms 24816 KB Output is correct
20 Correct 193 ms 25808 KB Output is correct
21 Correct 170 ms 25448 KB Output is correct
22 Correct 199 ms 25264 KB Output is correct
23 Correct 214 ms 25468 KB Output is correct
24 Correct 218 ms 25200 KB Output is correct
25 Correct 209 ms 25564 KB Output is correct
26 Correct 224 ms 25624 KB Output is correct
27 Correct 201 ms 25536 KB Output is correct
28 Correct 209 ms 25836 KB Output is correct
29 Correct 200 ms 23224 KB Output is correct
30 Correct 206 ms 24168 KB Output is correct
31 Correct 7 ms 1164 KB Output is correct
32 Correct 7 ms 1028 KB Output is correct
33 Correct 10 ms 1416 KB Output is correct
34 Correct 6 ms 1252 KB Output is correct
35 Correct 6 ms 900 KB Output is correct
36 Correct 5 ms 900 KB Output is correct
37 Correct 2 ms 908 KB Output is correct
38 Correct 3 ms 900 KB Output is correct
39 Correct 5 ms 908 KB Output is correct
40 Correct 5 ms 1036 KB Output is correct
41 Correct 6 ms 1268 KB Output is correct
42 Correct 6 ms 772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1164 KB Output is correct
2 Correct 6 ms 1164 KB Output is correct
3 Correct 7 ms 1064 KB Output is correct
4 Correct 41 ms 4992 KB Output is correct
5 Correct 35 ms 4788 KB Output is correct
6 Correct 37 ms 4992 KB Output is correct
7 Correct 40 ms 4820 KB Output is correct
8 Correct 33 ms 4948 KB Output is correct
9 Correct 169 ms 26188 KB Output is correct
10 Correct 162 ms 26252 KB Output is correct
11 Correct 192 ms 26148 KB Output is correct
12 Correct 6 ms 880 KB Output is correct
13 Correct 5 ms 908 KB Output is correct
14 Correct 5 ms 772 KB Output is correct
15 Correct 5 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 26380 KB Output is correct
2 Correct 280 ms 26324 KB Output is correct
3 Correct 246 ms 26708 KB Output is correct
4 Correct 204 ms 24940 KB Output is correct
5 Correct 233 ms 25836 KB Output is correct
6 Correct 219 ms 25592 KB Output is correct
7 Correct 202 ms 25600 KB Output is correct
8 Correct 201 ms 25184 KB Output is correct
9 Correct 234 ms 25416 KB Output is correct
10 Correct 184 ms 25080 KB Output is correct
11 Correct 197 ms 24964 KB Output is correct
12 Correct 186 ms 22876 KB Output is correct
13 Correct 202 ms 22788 KB Output is correct
14 Correct 219 ms 23876 KB Output is correct
15 Correct 215 ms 24992 KB Output is correct
16 Correct 211 ms 24828 KB Output is correct
17 Correct 192 ms 24940 KB Output is correct
18 Correct 193 ms 24896 KB Output is correct
19 Correct 192 ms 24972 KB Output is correct
20 Correct 162 ms 25752 KB Output is correct
21 Correct 191 ms 25208 KB Output is correct
22 Correct 187 ms 25704 KB Output is correct
23 Correct 207 ms 25320 KB Output is correct
24 Correct 203 ms 25376 KB Output is correct
25 Correct 201 ms 25580 KB Output is correct
26 Correct 205 ms 25456 KB Output is correct
27 Correct 201 ms 25556 KB Output is correct
28 Correct 254 ms 25412 KB Output is correct
29 Correct 178 ms 23084 KB Output is correct
30 Correct 196 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 229 ms 26432 KB Output is correct
2 Correct 209 ms 26344 KB Output is correct
3 Correct 209 ms 26444 KB Output is correct
4 Correct 207 ms 25072 KB Output is correct
5 Correct 200 ms 25960 KB Output is correct
6 Correct 189 ms 25328 KB Output is correct
7 Correct 196 ms 25200 KB Output is correct
8 Correct 210 ms 25504 KB Output is correct
9 Correct 198 ms 25436 KB Output is correct
10 Correct 178 ms 24904 KB Output is correct
11 Correct 222 ms 25136 KB Output is correct
12 Correct 174 ms 22580 KB Output is correct
13 Correct 186 ms 22780 KB Output is correct
14 Correct 212 ms 23756 KB Output is correct
15 Correct 223 ms 24900 KB Output is correct
16 Correct 221 ms 25000 KB Output is correct
17 Correct 224 ms 24932 KB Output is correct
18 Correct 211 ms 24796 KB Output is correct
19 Correct 244 ms 25024 KB Output is correct
20 Correct 172 ms 25616 KB Output is correct
21 Correct 162 ms 25216 KB Output is correct
22 Correct 191 ms 25488 KB Output is correct
23 Correct 244 ms 25544 KB Output is correct
24 Correct 210 ms 25376 KB Output is correct
25 Correct 219 ms 25352 KB Output is correct
26 Correct 219 ms 25204 KB Output is correct
27 Correct 205 ms 25860 KB Output is correct
28 Correct 210 ms 25636 KB Output is correct
29 Correct 196 ms 23592 KB Output is correct
30 Correct 205 ms 24216 KB Output is correct
31 Correct 6 ms 1252 KB Output is correct
32 Correct 6 ms 1156 KB Output is correct
33 Correct 8 ms 1416 KB Output is correct
34 Correct 7 ms 1224 KB Output is correct
35 Correct 6 ms 1028 KB Output is correct
36 Correct 5 ms 916 KB Output is correct
37 Correct 6 ms 908 KB Output is correct
38 Correct 4 ms 908 KB Output is correct
39 Correct 6 ms 900 KB Output is correct
40 Correct 6 ms 1036 KB Output is correct
41 Correct 6 ms 900 KB Output is correct
42 Correct 6 ms 924 KB Output is correct