답안 #406585

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
406585 2021-05-17T19:08:54 Z priority_queue 기지국 (IOI20_stations) C++14
100 / 100
1160 ms 652 KB
#include <bits/stdc++.h>

#define forint(i, N) for (int i = 0; i < (N); i++)

using namespace std;

vector<int> value;
vector<bool> visited;

int minval = 0;

void go(vector< vector<int> >& graph, int n, bool odd) {

	visited[n] = true;

	if (odd) {
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
		value[n] = minval;
		minval++;
	}
	else {
		value[n] = minval;
		minval++;
		for (auto& i : graph[n]) {
			if (!visited[i]) {
				go(graph, i, !odd);
			}
		}
	}
	
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector< vector<int> > graph(n);

	visited.clear();
	visited.resize(n);
	fill(visited.begin(), visited.end(), false);

	value.clear();
	value.resize(n);
	fill(value.begin(), value.end(), -1);

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

	minval = 0;
	go(graph, 0, true);

	return value;
}


int find_next_station(int s, int t, vector<int> c) {

	if (c.size() == 1) {
		return c[0];
	}	
	
	if (s < c[0]) {
		if (t < s || t > c[c.size() - 1]) {
			return c[c.size() - 1];
		}

		if (t <= c[0]) {
			return c[0];
		}
	}
	else {
		if (t > s || t < c[0]) {
			return c[0];
		}
		if (t >= c[c.size() - 1]) {
			return c[c.size() - 1];
		}
	}

  	if (s < c[0]) {
		if (t < s || t > c[c.size() - 1]) {
			return c[c.size() - 1];
		}
		forint(i, c.size()) {
			if (c[i] >= t) {
				return c[i];
			}
		}
	}
	else {
		if (t > s || t < c[0]) {
			return c[0];
		}
		for (int i = c.size() - 1; i >= 0; i--) {
			if (t >= c[i]) {
				return c[i];
			}
		}
	}

}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:3:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define forint(i, N) for (int i = 0; i < (N); i++)
      |                                        ^
stations.cpp:88:3: note: in expansion of macro 'forint'
   88 |   forint(i, c.size()) {
      |   ^~~~~~
stations.cpp:105:1: warning: control reaches end of non-void function [-Wreturn-type]
  105 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 701 ms 528 KB Output is correct
2 Correct 595 ms 604 KB Output is correct
3 Correct 1103 ms 400 KB Output is correct
4 Correct 811 ms 584 KB Output is correct
5 Correct 819 ms 484 KB Output is correct
6 Correct 423 ms 560 KB Output is correct
7 Correct 435 ms 528 KB Output is correct
8 Correct 3 ms 476 KB Output is correct
9 Correct 6 ms 476 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 505 ms 488 KB Output is correct
2 Correct 651 ms 488 KB Output is correct
3 Correct 1109 ms 528 KB Output is correct
4 Correct 850 ms 520 KB Output is correct
5 Correct 683 ms 492 KB Output is correct
6 Correct 509 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 538 ms 520 KB Output is correct
2 Correct 608 ms 492 KB Output is correct
3 Correct 1000 ms 428 KB Output is correct
4 Correct 802 ms 528 KB Output is correct
5 Correct 679 ms 496 KB Output is correct
6 Correct 574 ms 520 KB Output is correct
7 Correct 543 ms 528 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 599 ms 492 KB Output is correct
12 Correct 569 ms 564 KB Output is correct
13 Correct 647 ms 612 KB Output is correct
14 Correct 604 ms 528 KB Output is correct
15 Correct 42 ms 448 KB Output is correct
16 Correct 84 ms 520 KB Output is correct
17 Correct 114 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1069 ms 400 KB Output is correct
2 Correct 785 ms 652 KB Output is correct
3 Correct 798 ms 488 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 678 ms 400 KB Output is correct
8 Correct 1103 ms 400 KB Output is correct
9 Correct 705 ms 400 KB Output is correct
10 Correct 657 ms 400 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 5 ms 468 KB Output is correct
13 Correct 7 ms 488 KB Output is correct
14 Correct 4 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 657 ms 404 KB Output is correct
17 Correct 724 ms 428 KB Output is correct
18 Correct 633 ms 400 KB Output is correct
19 Correct 628 ms 400 KB Output is correct
20 Correct 713 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 715 ms 524 KB Output is correct
2 Correct 532 ms 488 KB Output is correct
3 Correct 1160 ms 400 KB Output is correct
4 Correct 951 ms 400 KB Output is correct
5 Correct 570 ms 400 KB Output is correct
6 Correct 557 ms 528 KB Output is correct
7 Correct 676 ms 484 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 645 ms 472 KB Output is correct
12 Correct 679 ms 528 KB Output is correct
13 Correct 1049 ms 472 KB Output is correct
14 Correct 945 ms 472 KB Output is correct
15 Correct 597 ms 400 KB Output is correct
16 Correct 601 ms 492 KB Output is correct
17 Correct 625 ms 400 KB Output is correct
18 Correct 560 ms 520 KB Output is correct
19 Correct 551 ms 652 KB Output is correct
20 Correct 597 ms 600 KB Output is correct
21 Correct 73 ms 448 KB Output is correct
22 Correct 79 ms 528 KB Output is correct
23 Correct 148 ms 536 KB Output is correct
24 Correct 7 ms 476 KB Output is correct
25 Correct 6 ms 476 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 6 ms 468 KB Output is correct
28 Correct 2 ms 476 KB Output is correct
29 Correct 636 ms 400 KB Output is correct
30 Correct 631 ms 488 KB Output is correct
31 Correct 723 ms 400 KB Output is correct
32 Correct 560 ms 484 KB Output is correct
33 Correct 761 ms 400 KB Output is correct
34 Correct 470 ms 528 KB Output is correct
35 Correct 507 ms 652 KB Output is correct
36 Correct 504 ms 528 KB Output is correct
37 Correct 579 ms 608 KB Output is correct
38 Correct 501 ms 476 KB Output is correct
39 Correct 577 ms 604 KB Output is correct
40 Correct 554 ms 648 KB Output is correct
41 Correct 484 ms 608 KB Output is correct
42 Correct 63 ms 556 KB Output is correct
43 Correct 104 ms 532 KB Output is correct
44 Correct 180 ms 528 KB Output is correct
45 Correct 224 ms 576 KB Output is correct
46 Correct 388 ms 484 KB Output is correct
47 Correct 381 ms 488 KB Output is correct
48 Correct 56 ms 556 KB Output is correct
49 Correct 81 ms 584 KB Output is correct