답안 #304942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304942 2020-09-22T09:00:18 Z Namnamseo 기지국 (IOI20_stations) C++17
100 / 100
1287 ms 1284 KB
#include <vector>
#include <algorithm>
using namespace std;

vector<int> edges[1010];
int n;

vector<int> dfs(int x, int p, int d)
{
	vector<int> cv;
	for(int y:edges[x]) if (y != p) {
		auto tmp = dfs(y, x, d+1);
		cv.insert(cv.end(), tmp.begin(), tmp.end());
	}
	if (d%2 == 0) cv.insert(cv.begin(), x);
	else cv.insert(cv.end(), x);

	return cv;
}

vector<int> label(int n_, int k, vector<int> u, vector<int> v)
{
	n = n_;
	for(int i=0; i<n; ++i) edges[i].clear();

	for(int i=0; i<n-1; ++i) {
		int a = u[i], b = v[i];
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	auto eu = dfs(0, -1, 0);

	vector<int> lbl(n);
	for(int i=0; i<n; ++i) lbl[eu[i]] = i;

	return lbl;
}

int find_next_station(int s, int t, vector<int> c)
{
	if (c.size() == 1u) return c[0];

	if (s > c[0]) {
		int sz = int(c.size()) - 1;
		c.push_back(s);
		for(int i=1; i<=sz; ++i) {
			int l = c[i], r = c[i+1]-1;
			if (l <= t && t <= r) return c[i];
		}
		return c[0];
	} else {
		rotate(c.begin(), c.end()-1, c.end());
		int sz = int(c.size()) - 1;
		c.insert(c.begin()+1, s);
		for(int i=2; i<=sz+1; ++i) {
			int r = c[i], l = c[i-1]+1;
			if (l <= t && t <= r) return c[i];
		}
		return c[0];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 749 ms 1016 KB Output is correct
2 Correct 620 ms 1024 KB Output is correct
3 Correct 1043 ms 888 KB Output is correct
4 Correct 788 ms 768 KB Output is correct
5 Correct 764 ms 896 KB Output is correct
6 Correct 550 ms 1008 KB Output is correct
7 Correct 501 ms 1056 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 578 ms 832 KB Output is correct
2 Correct 622 ms 760 KB Output is correct
3 Correct 1287 ms 752 KB Output is correct
4 Correct 716 ms 904 KB Output is correct
5 Correct 734 ms 896 KB Output is correct
6 Correct 468 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 628 ms 1016 KB Output is correct
2 Correct 561 ms 1008 KB Output is correct
3 Correct 1099 ms 760 KB Output is correct
4 Correct 859 ms 896 KB Output is correct
5 Correct 737 ms 1020 KB Output is correct
6 Correct 541 ms 1024 KB Output is correct
7 Correct 600 ms 1024 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 775 ms 768 KB Output is correct
12 Correct 536 ms 1008 KB Output is correct
13 Correct 718 ms 1024 KB Output is correct
14 Correct 517 ms 776 KB Output is correct
15 Correct 65 ms 880 KB Output is correct
16 Correct 75 ms 776 KB Output is correct
17 Correct 112 ms 788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1035 ms 896 KB Output is correct
2 Correct 859 ms 780 KB Output is correct
3 Correct 720 ms 768 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 896 KB Output is correct
6 Correct 1 ms 820 KB Output is correct
7 Correct 803 ms 896 KB Output is correct
8 Correct 1035 ms 764 KB Output is correct
9 Correct 895 ms 760 KB Output is correct
10 Correct 660 ms 896 KB Output is correct
11 Correct 9 ms 776 KB Output is correct
12 Correct 7 ms 768 KB Output is correct
13 Correct 6 ms 896 KB Output is correct
14 Correct 6 ms 896 KB Output is correct
15 Correct 2 ms 896 KB Output is correct
16 Correct 592 ms 928 KB Output is correct
17 Correct 747 ms 768 KB Output is correct
18 Correct 688 ms 768 KB Output is correct
19 Correct 658 ms 768 KB Output is correct
20 Correct 605 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 698 ms 1024 KB Output is correct
2 Correct 565 ms 1056 KB Output is correct
3 Correct 1045 ms 800 KB Output is correct
4 Correct 832 ms 764 KB Output is correct
5 Correct 724 ms 784 KB Output is correct
6 Correct 506 ms 1024 KB Output is correct
7 Correct 576 ms 1024 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 554 ms 928 KB Output is correct
12 Correct 647 ms 768 KB Output is correct
13 Correct 1156 ms 760 KB Output is correct
14 Correct 909 ms 768 KB Output is correct
15 Correct 866 ms 768 KB Output is correct
16 Correct 509 ms 800 KB Output is correct
17 Correct 729 ms 1016 KB Output is correct
18 Correct 508 ms 1052 KB Output is correct
19 Correct 529 ms 1284 KB Output is correct
20 Correct 562 ms 768 KB Output is correct
21 Correct 55 ms 768 KB Output is correct
22 Correct 91 ms 768 KB Output is correct
23 Correct 136 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 4 ms 768 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 3 ms 776 KB Output is correct
29 Correct 655 ms 640 KB Output is correct
30 Correct 644 ms 776 KB Output is correct
31 Correct 667 ms 688 KB Output is correct
32 Correct 648 ms 888 KB Output is correct
33 Correct 614 ms 896 KB Output is correct
34 Correct 544 ms 1008 KB Output is correct
35 Correct 421 ms 1024 KB Output is correct
36 Correct 550 ms 1024 KB Output is correct
37 Correct 595 ms 1008 KB Output is correct
38 Correct 601 ms 896 KB Output is correct
39 Correct 453 ms 896 KB Output is correct
40 Correct 617 ms 1008 KB Output is correct
41 Correct 490 ms 964 KB Output is correct
42 Correct 77 ms 768 KB Output is correct
43 Correct 160 ms 768 KB Output is correct
44 Correct 203 ms 872 KB Output is correct
45 Correct 251 ms 896 KB Output is correct
46 Correct 333 ms 768 KB Output is correct
47 Correct 315 ms 768 KB Output is correct
48 Correct 80 ms 768 KB Output is correct
49 Correct 91 ms 1024 KB Output is correct