답안 #388392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388392 2021-04-11T09:52:07 Z JimmyZJX 기지국 (IOI20_stations) C++14
100 / 100
1087 ms 864 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cassert>
#include <tuple>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;

typedef long long LL;
typedef vector<int> Vi;
typedef vector<bool> Vb;
typedef vector<vector<int>> Vii;

#define forR(i, n) for (int i = 0; i < (n); i++)

Vb visited;
Vii nbs;
int l;
Vi labels;

void dfs(int x, int mode) { // 0: start, 1: end
	visited[x] = true;
	if (mode == 0) labels[x] = l++;

	for (int nb : nbs[x]) {
		if (visited[nb]) continue;
		dfs(nb, 1 - mode);
	}

	if (mode == 1) labels[x] = l++;
}

Vi label(int n, int k, Vi u, Vi v) {
	l = 0;
	labels = Vi(n);
	nbs = Vii(n);
	visited = Vb(n);

	forR(i, n - 1) {
		nbs[u[i]].push_back(v[i]);
		nbs[v[i]].push_back(u[i]);
	}

	dfs(0, 0);
	assert(l == n);

	return labels;
}

int find_next_station(int s, int t, Vi c) {
	if (s < c[0]) {
		// s.mode == 0
		int start = s;
		for (int end : c) {
			if (t >= start && t <= end) return end;
		}
		return c.back();
	} else {
		// s.mode == 1
		int end = s;
		for (auto it = c.rbegin(); it != c.rend(); it++) {
			int start = *it;
			if (t >= start && t <= end) return start;
		}
		return c[0];
	}
}

#ifdef TEST_LOCAL
int main() {
	auto lbs = label(5, 10, Vi{ 0, 1, 1, 2 }, Vi{ 1, 2, 3, 4 });

	return 0;
}
#endif

# 결과 실행 시간 메모리 Grader output
1 Correct 595 ms 684 KB Output is correct
2 Correct 534 ms 656 KB Output is correct
3 Correct 1051 ms 400 KB Output is correct
4 Correct 766 ms 492 KB Output is correct
5 Correct 691 ms 536 KB Output is correct
6 Correct 523 ms 528 KB Output is correct
7 Correct 566 ms 496 KB Output is correct
8 Correct 2 ms 472 KB Output is correct
9 Correct 3 ms 472 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 437 ms 728 KB Output is correct
2 Correct 610 ms 528 KB Output is correct
3 Correct 1083 ms 488 KB Output is correct
4 Correct 843 ms 504 KB Output is correct
5 Correct 730 ms 400 KB Output is correct
6 Correct 616 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 616 KB Output is correct
2 Correct 533 ms 620 KB Output is correct
3 Correct 1087 ms 400 KB Output is correct
4 Correct 831 ms 400 KB Output is correct
5 Correct 746 ms 400 KB Output is correct
6 Correct 507 ms 528 KB Output is correct
7 Correct 576 ms 528 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 707 ms 400 KB Output is correct
12 Correct 506 ms 736 KB Output is correct
13 Correct 475 ms 732 KB Output is correct
14 Correct 495 ms 484 KB Output is correct
15 Correct 70 ms 400 KB Output is correct
16 Correct 78 ms 528 KB Output is correct
17 Correct 125 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1012 ms 400 KB Output is correct
2 Correct 734 ms 408 KB Output is correct
3 Correct 757 ms 400 KB Output is correct
4 Correct 3 ms 472 KB Output is correct
5 Correct 4 ms 476 KB Output is correct
6 Correct 1 ms 472 KB Output is correct
7 Correct 717 ms 492 KB Output is correct
8 Correct 1009 ms 400 KB Output is correct
9 Correct 674 ms 488 KB Output is correct
10 Correct 785 ms 400 KB Output is correct
11 Correct 6 ms 476 KB Output is correct
12 Correct 5 ms 472 KB Output is correct
13 Correct 6 ms 476 KB Output is correct
14 Correct 4 ms 472 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 519 ms 400 KB Output is correct
17 Correct 465 ms 400 KB Output is correct
18 Correct 627 ms 400 KB Output is correct
19 Correct 617 ms 400 KB Output is correct
20 Correct 585 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 648 KB Output is correct
2 Correct 522 ms 628 KB Output is correct
3 Correct 1002 ms 404 KB Output is correct
4 Correct 840 ms 496 KB Output is correct
5 Correct 671 ms 488 KB Output is correct
6 Correct 575 ms 616 KB Output is correct
7 Correct 504 ms 472 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 4 ms 472 KB Output is correct
10 Correct 1 ms 472 KB Output is correct
11 Correct 481 ms 528 KB Output is correct
12 Correct 506 ms 484 KB Output is correct
13 Correct 991 ms 400 KB Output is correct
14 Correct 836 ms 488 KB Output is correct
15 Correct 746 ms 400 KB Output is correct
16 Correct 563 ms 480 KB Output is correct
17 Correct 731 ms 496 KB Output is correct
18 Correct 528 ms 744 KB Output is correct
19 Correct 563 ms 736 KB Output is correct
20 Correct 578 ms 484 KB Output is correct
21 Correct 46 ms 420 KB Output is correct
22 Correct 83 ms 528 KB Output is correct
23 Correct 142 ms 528 KB Output is correct
24 Correct 6 ms 472 KB Output is correct
25 Correct 7 ms 472 KB Output is correct
26 Correct 4 ms 476 KB Output is correct
27 Correct 4 ms 472 KB Output is correct
28 Correct 1 ms 472 KB Output is correct
29 Correct 629 ms 488 KB Output is correct
30 Correct 629 ms 400 KB Output is correct
31 Correct 652 ms 488 KB Output is correct
32 Correct 618 ms 400 KB Output is correct
33 Correct 654 ms 600 KB Output is correct
34 Correct 404 ms 648 KB Output is correct
35 Correct 478 ms 864 KB Output is correct
36 Correct 524 ms 660 KB Output is correct
37 Correct 627 ms 652 KB Output is correct
38 Correct 558 ms 608 KB Output is correct
39 Correct 609 ms 608 KB Output is correct
40 Correct 643 ms 828 KB Output is correct
41 Correct 441 ms 748 KB Output is correct
42 Correct 83 ms 564 KB Output is correct
43 Correct 104 ms 528 KB Output is correct
44 Correct 175 ms 528 KB Output is correct
45 Correct 237 ms 528 KB Output is correct
46 Correct 400 ms 492 KB Output is correct
47 Correct 311 ms 620 KB Output is correct
48 Correct 54 ms 544 KB Output is correct
49 Correct 75 ms 676 KB Output is correct