Submission #304908

# Submission time Handle Problem Language Result Execution time Memory
304908 2020-09-22T07:40:46 Z model_code Stations (IOI20_stations) C++17
100 / 100
1236 ms 1520 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> sz, labels;
vector<vector<int>> E;
int dfsSiz(int x, int p = -1) {
	sz[x] = 1;
	for (int y : E[x]) {
		if (y == p) continue;
		sz[x] += dfsSiz(y, x);
	}
	return sz[x];
}
void dfs(int x, int s, int e, int p = -1, int h = 0) {
	if (h & 1) {
		labels[x] = e--;
	} else {
		labels[x] = s++;
	}
	for (int y : E[x]) {
		if (y == p) continue;
		dfs(y, s, s + sz[y] - 1, x, h + 1);
		s += sz[y];
	}
	assert(s == e + 1);
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	assert(u.size() == n - 1 && v.size() == n - 1);
	sz = vector<int>(n);
	labels = vector<int>(n);
	E = vector<vector<int>>(n);
	for (int i = 0; i < n - 1; ++i) {
		E[u[i]].push_back(v[i]);
		E[v[i]].push_back(u[i]);
	}
	dfsSiz(0);
	dfs(0, 0, n - 1);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	vector<int> sub{s, s};
	int m = c.size();
	if (c[0] < s) {
		if (m > 1) sub[0] = c[1];
		if (t < sub[0] || t > sub[1]) return c[0];
		for (int i = 1; i + 1 < m; ++i)
			if (c[i + 1] > t) return c[i];
		return c[m - 1];
	} else {
		if (s != 0 && m > 1) sub[1] = c[m - 2];
		else if (s == 0) sub[1] = c[m - 1];
		if (t < sub[0] || t > sub[1]) return c[m - 1];
		for (int i = 0;; ++i)
			if (c[i] >= t) return c[i];
	}
}

Compilation message

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from stations.cpp:2:
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:28:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |  assert(u.size() == n - 1 && v.size() == n - 1);
      |         ~~~~~~~~~^~~~~~~~
stations.cpp:28:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |  assert(u.size() == n - 1 && v.size() == n - 1);
      |                              ~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 765 ms 1004 KB Output is correct
2 Correct 654 ms 1024 KB Output is correct
3 Correct 1162 ms 748 KB Output is correct
4 Correct 846 ms 640 KB Output is correct
5 Correct 594 ms 652 KB Output is correct
6 Correct 612 ms 1000 KB Output is correct
7 Correct 610 ms 1016 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 1000 KB Output is correct
2 Correct 714 ms 896 KB Output is correct
3 Correct 1061 ms 880 KB Output is correct
4 Correct 713 ms 788 KB Output is correct
5 Correct 658 ms 768 KB Output is correct
6 Correct 492 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 890 ms 1008 KB Output is correct
2 Correct 574 ms 1024 KB Output is correct
3 Correct 1075 ms 768 KB Output is correct
4 Correct 812 ms 640 KB Output is correct
5 Correct 842 ms 640 KB Output is correct
6 Correct 609 ms 1024 KB Output is correct
7 Correct 607 ms 768 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 6 ms 640 KB Output is correct
10 Correct 2 ms 640 KB Output is correct
11 Correct 784 ms 640 KB Output is correct
12 Correct 507 ms 1024 KB Output is correct
13 Correct 598 ms 1024 KB Output is correct
14 Correct 479 ms 1016 KB Output is correct
15 Correct 63 ms 768 KB Output is correct
16 Correct 84 ms 768 KB Output is correct
17 Correct 109 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1077 ms 768 KB Output is correct
2 Correct 790 ms 800 KB Output is correct
3 Correct 755 ms 768 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 2 ms 904 KB Output is correct
7 Correct 618 ms 768 KB Output is correct
8 Correct 1123 ms 744 KB Output is correct
9 Correct 767 ms 768 KB Output is correct
10 Correct 830 ms 756 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 3 ms 640 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 2 ms 652 KB Output is correct
16 Correct 651 ms 800 KB Output is correct
17 Correct 504 ms 800 KB Output is correct
18 Correct 699 ms 640 KB Output is correct
19 Correct 593 ms 800 KB Output is correct
20 Correct 712 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 702 ms 1024 KB Output is correct
2 Correct 558 ms 1072 KB Output is correct
3 Correct 1006 ms 680 KB Output is correct
4 Correct 748 ms 880 KB Output is correct
5 Correct 839 ms 904 KB Output is correct
6 Correct 524 ms 1024 KB Output is correct
7 Correct 614 ms 928 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 776 KB Output is correct
11 Correct 545 ms 984 KB Output is correct
12 Correct 768 ms 932 KB Output is correct
13 Correct 1236 ms 776 KB Output is correct
14 Correct 701 ms 768 KB Output is correct
15 Correct 820 ms 768 KB Output is correct
16 Correct 718 ms 896 KB Output is correct
17 Correct 1000 ms 640 KB Output is correct
18 Correct 674 ms 1008 KB Output is correct
19 Correct 709 ms 1096 KB Output is correct
20 Correct 519 ms 744 KB Output is correct
21 Correct 55 ms 776 KB Output is correct
22 Correct 90 ms 776 KB Output is correct
23 Correct 163 ms 1000 KB Output is correct
24 Correct 5 ms 788 KB Output is correct
25 Correct 6 ms 640 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 533 ms 760 KB Output is correct
30 Correct 605 ms 800 KB Output is correct
31 Correct 626 ms 640 KB Output is correct
32 Correct 643 ms 1024 KB Output is correct
33 Correct 659 ms 768 KB Output is correct
34 Correct 509 ms 1520 KB Output is correct
35 Correct 535 ms 1156 KB Output is correct
36 Correct 549 ms 1024 KB Output is correct
37 Correct 516 ms 880 KB Output is correct
38 Correct 592 ms 1016 KB Output is correct
39 Correct 444 ms 1008 KB Output is correct
40 Correct 572 ms 1020 KB Output is correct
41 Correct 640 ms 996 KB Output is correct
42 Correct 87 ms 1192 KB Output is correct
43 Correct 151 ms 1024 KB Output is correct
44 Correct 143 ms 780 KB Output is correct
45 Correct 217 ms 768 KB Output is correct
46 Correct 403 ms 768 KB Output is correct
47 Correct 411 ms 1064 KB Output is correct
48 Correct 83 ms 1000 KB Output is correct
49 Correct 86 ms 976 KB Output is correct