답안 #799585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
799585 2023-07-31T16:16:00 Z QwertyPi 기지국 (IOI20_stations) C++14
100 / 100
717 ms 776 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e3 + 11;
vector<int> G[MAXN];
int sz[MAXN], L[MAXN];

void dfs_prec(int v, int pa = -1){
	int _sz = 1;
	for(auto u : G[v]){
		if(u != pa){
			dfs_prec(u, v); _sz += sz[u];
		}
	}
	sz[v] = _sz;
}

void dfs_label(int v, int pa, int l, int r, bool large){
	L[v] = large ? r-- : l++;
	for(auto u : G[v]){
		if(u != pa){
			dfs_label(u, v, l, l + sz[u] - 1, !large); l += sz[u];
		}
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for(int i = 0; i < n; i++){
		G[i].clear();
	}
	for(int i = 0; i < n - 1; i++){
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	dfs_prec(0);
	dfs_label(0, -1, 0, n - 1, true);
	vector<int> labels(n);
	for(int i = 0; i < n; i++){
		labels[i] = L[i];
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size() == 1) return c[0];
	sort(c.begin(), c.end());
	if(s < c[0]){
		for(int i = 0; i < (int) c.size() - 1; i++){
			if(c[i] >= t && t >= s) return c[i];
		}
		return c[(int) c.size() - 1];
	}else{
		for(int i = (int) c.size() - 1; i >= 1; i--){
			if(c[i] <= t && t <= s) return c[i];
		}
		return c[0];
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 544 KB Output is correct
2 Correct 363 ms 672 KB Output is correct
3 Correct 639 ms 416 KB Output is correct
4 Correct 561 ms 416 KB Output is correct
5 Correct 570 ms 596 KB Output is correct
6 Correct 342 ms 636 KB Output is correct
7 Correct 375 ms 536 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 544 KB Output is correct
2 Correct 392 ms 552 KB Output is correct
3 Correct 641 ms 536 KB Output is correct
4 Correct 535 ms 416 KB Output is correct
5 Correct 432 ms 420 KB Output is correct
6 Correct 325 ms 652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 656 KB Output is correct
2 Correct 330 ms 660 KB Output is correct
3 Correct 664 ms 420 KB Output is correct
4 Correct 524 ms 540 KB Output is correct
5 Correct 464 ms 532 KB Output is correct
6 Correct 344 ms 664 KB Output is correct
7 Correct 373 ms 528 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 526 ms 420 KB Output is correct
12 Correct 363 ms 672 KB Output is correct
13 Correct 368 ms 744 KB Output is correct
14 Correct 321 ms 532 KB Output is correct
15 Correct 47 ms 620 KB Output is correct
16 Correct 53 ms 716 KB Output is correct
17 Correct 82 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 665 ms 420 KB Output is correct
2 Correct 546 ms 416 KB Output is correct
3 Correct 440 ms 460 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 542 ms 532 KB Output is correct
8 Correct 717 ms 508 KB Output is correct
9 Correct 592 ms 532 KB Output is correct
10 Correct 421 ms 536 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 395 ms 536 KB Output is correct
17 Correct 452 ms 536 KB Output is correct
18 Correct 438 ms 548 KB Output is correct
19 Correct 480 ms 540 KB Output is correct
20 Correct 397 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 324 ms 676 KB Output is correct
2 Correct 280 ms 660 KB Output is correct
3 Correct 714 ms 528 KB Output is correct
4 Correct 622 ms 532 KB Output is correct
5 Correct 539 ms 528 KB Output is correct
6 Correct 315 ms 660 KB Output is correct
7 Correct 379 ms 524 KB Output is correct
8 Correct 1 ms 500 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 0 ms 500 KB Output is correct
11 Correct 412 ms 660 KB Output is correct
12 Correct 353 ms 540 KB Output is correct
13 Correct 677 ms 420 KB Output is correct
14 Correct 431 ms 416 KB Output is correct
15 Correct 507 ms 532 KB Output is correct
16 Correct 447 ms 532 KB Output is correct
17 Correct 500 ms 532 KB Output is correct
18 Correct 321 ms 652 KB Output is correct
19 Correct 334 ms 652 KB Output is correct
20 Correct 310 ms 540 KB Output is correct
21 Correct 47 ms 620 KB Output is correct
22 Correct 61 ms 604 KB Output is correct
23 Correct 74 ms 656 KB Output is correct
24 Correct 2 ms 500 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 4 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 374 ms 536 KB Output is correct
30 Correct 355 ms 420 KB Output is correct
31 Correct 380 ms 420 KB Output is correct
32 Correct 419 ms 528 KB Output is correct
33 Correct 471 ms 540 KB Output is correct
34 Correct 214 ms 640 KB Output is correct
35 Correct 375 ms 664 KB Output is correct
36 Correct 382 ms 776 KB Output is correct
37 Correct 374 ms 628 KB Output is correct
38 Correct 317 ms 644 KB Output is correct
39 Correct 422 ms 704 KB Output is correct
40 Correct 407 ms 644 KB Output is correct
41 Correct 304 ms 620 KB Output is correct
42 Correct 46 ms 600 KB Output is correct
43 Correct 54 ms 672 KB Output is correct
44 Correct 104 ms 616 KB Output is correct
45 Correct 119 ms 600 KB Output is correct
46 Correct 271 ms 548 KB Output is correct
47 Correct 295 ms 528 KB Output is correct
48 Correct 37 ms 676 KB Output is correct
49 Correct 50 ms 736 KB Output is correct