답안 #1052425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052425 2024-08-10T14:27:26 Z MercubytheFirst 기지국 (IOI20_stations) C++17
73.3618 / 100
521 ms 1192 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>

namespace label_call {
	using std::vector;
	using std::cout;
	using std::max;
	using std::endl;

	vector<vector<int> > g;
	int timer = 0;
	vector<int> tin, tout, ans;
	void dfs(int v, int par, int dep) {
		tin[v] = timer;
		timer += 1;
		for(int child : g[v]) {
			if(child == par) {
				continue;
			}
			dfs(child, v, dep + 1);
		}
		tout[v] = timer;
		timer += 1;

		if(dep % 2 == 1) {
			ans[v] = 2 * tout[v] + 1;
		}
		else {
			ans[v] = 2 * tin[v];
		}
	}

} // namespace label_call

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	using namespace label_call;
	g.assign(n, vector<int>());
	timer = 0;
	tin.assign(n, -1);
	tout.assign(n, -1);
	ans.assign(n, -1);
	for(int i = 0; i < n - 1; ++i) {
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	dfs(0, -1, 0);
	// assert(*std::max_element(ans.begin(), ans.end()) <= 4100);
	assert(*std::max_element(tout.begin(), tout.end()) <= 2000);
	return ans;
}


namespace query_call {
	using std::vector;
	using std::cout;
	using std::sort;
	using std::endl;
}

int find_next_station(signed s, signed t, std::vector<signed> c) {
	using namespace query_call;
	if(c.size() == 1u) {
		return c[0];
	}
	const int target_time = t/2;
	int tin = -1, tout = -1;
	if(s % 2 == 1) {
		tout = s/2;
		tin = c[1]/2 - 1;
		assert(tin != tout and tout != target_time and tin != target_time);
		if(target_time < tin or tout < target_time) {
			return c[0];
		}
		const int child_cnt = c.size();
		for(int i = child_cnt - 1; i >= 0; --i) {
			const int child_tin = c[i]/2;
			if(target_time >= child_tin) {
				return c[i];
			}
		}
	}
	else {
		sort(c.begin(), c.end(), std::greater<int>());
		tin = s/2;
		tout = c[1]/2 + 1;
		if(target_time < tin or tout < target_time) {
			return c[0];
		}
		const int child_cnt = c.size();
		for(int i = child_cnt - 1; i >= 0; --i) {
			const int child_tin = c[i]/2;
			if(target_time <= child_tin) {
				return c[i];
			}
		}
	}
	assert(false);
	return -1;
}

/*
1

5 20
0 1
1 2
1 3
2 4
6
0 3 1
3 2 1
3 4 1
1 4 2
0 1 1



1
14 60
0 1
1 2
2 3
2 4
2 5
5 6
5 7 
1 8
0 9
9 10
10 11
11 12
11 13
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=3981
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 428 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=2045
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 940 KB Output is correct
2 Correct 256 ms 1192 KB Output is correct
3 Correct 507 ms 684 KB Output is correct
4 Correct 370 ms 684 KB Output is correct
5 Correct 314 ms 684 KB Output is correct
6 Correct 280 ms 684 KB Output is correct
7 Correct 213 ms 680 KB Output is correct
8 Correct 0 ms 776 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 286 ms 768 KB Output is correct
12 Correct 232 ms 852 KB Output is correct
13 Correct 228 ms 760 KB Output is correct
14 Correct 237 ms 684 KB Output is correct
15 Correct 23 ms 768 KB Output is correct
16 Correct 31 ms 768 KB Output is correct
17 Correct 43 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 684 KB Output is correct
2 Correct 339 ms 684 KB Output is correct
3 Correct 276 ms 684 KB Output is correct
4 Correct 0 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 276 ms 688 KB Output is correct
8 Correct 465 ms 684 KB Output is correct
9 Correct 412 ms 940 KB Output is correct
10 Correct 329 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 764 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 278 ms 768 KB Output is correct
17 Correct 285 ms 684 KB Output is correct
18 Correct 266 ms 684 KB Output is correct
19 Correct 302 ms 684 KB Output is correct
20 Correct 294 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 331 ms 940 KB Partially correct
2 Partially correct 243 ms 932 KB Partially correct
3 Correct 521 ms 684 KB Output is correct
4 Correct 358 ms 684 KB Output is correct
5 Correct 352 ms 684 KB Output is correct
6 Partially correct 255 ms 936 KB Partially correct
7 Partially correct 255 ms 684 KB Partially correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 780 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Partially correct 273 ms 684 KB Partially correct
12 Partially correct 327 ms 684 KB Partially correct
13 Correct 514 ms 684 KB Output is correct
14 Correct 365 ms 684 KB Output is correct
15 Correct 310 ms 684 KB Output is correct
16 Partially correct 274 ms 684 KB Partially correct
17 Correct 311 ms 684 KB Output is correct
18 Partially correct 280 ms 684 KB Partially correct
19 Partially correct 238 ms 1020 KB Partially correct
20 Partially correct 254 ms 684 KB Partially correct
21 Correct 41 ms 768 KB Output is correct
22 Partially correct 32 ms 772 KB Partially correct
23 Partially correct 46 ms 764 KB Partially correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 764 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 1 ms 776 KB Output is correct
28 Correct 0 ms 776 KB Output is correct
29 Correct 270 ms 940 KB Output is correct
30 Correct 253 ms 684 KB Output is correct
31 Correct 274 ms 684 KB Output is correct
32 Correct 279 ms 940 KB Output is correct
33 Correct 267 ms 684 KB Output is correct
34 Partially correct 181 ms 932 KB Partially correct
35 Partially correct 267 ms 940 KB Partially correct
36 Partially correct 249 ms 940 KB Partially correct
37 Partially correct 246 ms 764 KB Partially correct
38 Partially correct 246 ms 772 KB Partially correct
39 Partially correct 258 ms 932 KB Partially correct
40 Partially correct 257 ms 776 KB Partially correct
41 Partially correct 278 ms 1020 KB Partially correct
42 Partially correct 32 ms 768 KB Partially correct
43 Partially correct 47 ms 744 KB Partially correct
44 Partially correct 74 ms 768 KB Partially correct
45 Partially correct 86 ms 764 KB Partially correct
46 Partially correct 168 ms 684 KB Partially correct
47 Partially correct 163 ms 684 KB Partially correct
48 Partially correct 27 ms 1052 KB Partially correct
49 Partially correct 30 ms 876 KB Partially correct