답안 #342404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342404 2021-01-02T05:29:11 Z Ta180m 기지국 (IOI20_stations) C++17
100 / 100
1184 ms 1236 KB
#include "stations.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1e3+5;

int cnt, in[MX], out[MX];
vector<int> labels, G[MX];

void dfs(int u, int p, int d) {
	in[u] = cnt++;
	for (int v : G[u]) if (v != p) dfs(v, u, d+1);
	out[u] = cnt++;
	labels[u] = (d%2 == 0 ? in[u] : out[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]);
	labels.resize(n, 0);
	cnt = 0;
	dfs(0, -1, 0);
	vector<int> tmp(begin(labels), end(labels));
	sort(begin(tmp), end(tmp));
	for (int i = 0; i < labels.size(); ++i)
		labels[i] = lower_bound(begin(tmp), end(tmp), labels[i])-begin(tmp);
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) return c[0];
	int m = *min_element(begin(c), end(c));
	if (s < m) {
		if (s == 0) {
			for (int i = 0; i < c.size(); ++i)
				if (t <= c[i]) return c[i];
		}
		else {
			int p = *max_element(begin(c), end(c));
			c.erase(find(begin(c), end(c), p));
			if (t < s) return p;
			for (int i = 0; i < c.size(); ++i)
				if (t <= c[i]) return c[i];
			return p;
		}
	}
	else {
		int p = m;
		c.erase(find(begin(c), end(c), p));
		if (t > s) return p;
		for (int i = c.size()-1; i >= 0; --i)
			if (t >= c[i]) return c[i];
		return p;
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < labels.size(); ++i)
      |                  ~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for (int i = 0; i < c.size(); ++i)
      |                    ~~^~~~~~~~~~
stations.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    for (int i = 0; i < c.size(); ++i)
      |                    ~~^~~~~~~~~~
stations.cpp:59:1: warning: control reaches end of non-void function [-Wreturn-type]
   59 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 1060 KB Output is correct
2 Correct 593 ms 1064 KB Output is correct
3 Correct 1184 ms 736 KB Output is correct
4 Correct 641 ms 864 KB Output is correct
5 Correct 680 ms 952 KB Output is correct
6 Correct 490 ms 864 KB Output is correct
7 Correct 490 ms 1168 KB Output is correct
8 Correct 3 ms 836 KB Output is correct
9 Correct 5 ms 864 KB Output is correct
10 Correct 2 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 548 ms 872 KB Output is correct
2 Correct 565 ms 736 KB Output is correct
3 Correct 927 ms 1072 KB Output is correct
4 Correct 611 ms 1108 KB Output is correct
5 Correct 590 ms 684 KB Output is correct
6 Correct 445 ms 864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 1004 KB Output is correct
2 Correct 442 ms 992 KB Output is correct
3 Correct 867 ms 864 KB Output is correct
4 Correct 690 ms 944 KB Output is correct
5 Correct 639 ms 944 KB Output is correct
6 Correct 506 ms 992 KB Output is correct
7 Correct 448 ms 1120 KB Output is correct
8 Correct 3 ms 944 KB Output is correct
9 Correct 5 ms 864 KB Output is correct
10 Correct 2 ms 952 KB Output is correct
11 Correct 792 ms 952 KB Output is correct
12 Correct 477 ms 1188 KB Output is correct
13 Correct 494 ms 992 KB Output is correct
14 Correct 468 ms 888 KB Output is correct
15 Correct 46 ms 840 KB Output is correct
16 Correct 65 ms 864 KB Output is correct
17 Correct 107 ms 872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 926 ms 736 KB Output is correct
2 Correct 765 ms 864 KB Output is correct
3 Correct 618 ms 864 KB Output is correct
4 Correct 3 ms 1072 KB Output is correct
5 Correct 4 ms 952 KB Output is correct
6 Correct 2 ms 864 KB Output is correct
7 Correct 610 ms 736 KB Output is correct
8 Correct 882 ms 944 KB Output is correct
9 Correct 728 ms 992 KB Output is correct
10 Correct 673 ms 944 KB Output is correct
11 Correct 6 ms 864 KB Output is correct
12 Correct 7 ms 736 KB Output is correct
13 Correct 6 ms 736 KB Output is correct
14 Correct 4 ms 736 KB Output is correct
15 Correct 2 ms 864 KB Output is correct
16 Correct 520 ms 1236 KB Output is correct
17 Correct 490 ms 864 KB Output is correct
18 Correct 559 ms 864 KB Output is correct
19 Correct 598 ms 1008 KB Output is correct
20 Correct 470 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 589 ms 992 KB Output is correct
2 Correct 490 ms 864 KB Output is correct
3 Correct 844 ms 864 KB Output is correct
4 Correct 645 ms 1108 KB Output is correct
5 Correct 586 ms 864 KB Output is correct
6 Correct 446 ms 992 KB Output is correct
7 Correct 429 ms 1104 KB Output is correct
8 Correct 3 ms 952 KB Output is correct
9 Correct 4 ms 864 KB Output is correct
10 Correct 2 ms 952 KB Output is correct
11 Correct 452 ms 736 KB Output is correct
12 Correct 567 ms 876 KB Output is correct
13 Correct 837 ms 864 KB Output is correct
14 Correct 637 ms 944 KB Output is correct
15 Correct 564 ms 944 KB Output is correct
16 Correct 454 ms 1016 KB Output is correct
17 Correct 538 ms 864 KB Output is correct
18 Correct 427 ms 1120 KB Output is correct
19 Correct 435 ms 1120 KB Output is correct
20 Correct 423 ms 1120 KB Output is correct
21 Correct 53 ms 936 KB Output is correct
22 Correct 64 ms 900 KB Output is correct
23 Correct 115 ms 864 KB Output is correct
24 Correct 5 ms 952 KB Output is correct
25 Correct 5 ms 864 KB Output is correct
26 Correct 4 ms 864 KB Output is correct
27 Correct 3 ms 864 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 504 ms 736 KB Output is correct
30 Correct 510 ms 952 KB Output is correct
31 Correct 509 ms 992 KB Output is correct
32 Correct 522 ms 864 KB Output is correct
33 Correct 467 ms 1148 KB Output is correct
34 Correct 323 ms 1072 KB Output is correct
35 Correct 446 ms 1064 KB Output is correct
36 Correct 516 ms 1064 KB Output is correct
37 Correct 471 ms 1068 KB Output is correct
38 Correct 630 ms 864 KB Output is correct
39 Correct 538 ms 1136 KB Output is correct
40 Correct 513 ms 1104 KB Output is correct
41 Correct 502 ms 1068 KB Output is correct
42 Correct 73 ms 888 KB Output is correct
43 Correct 123 ms 864 KB Output is correct
44 Correct 170 ms 864 KB Output is correct
45 Correct 212 ms 1104 KB Output is correct
46 Correct 311 ms 880 KB Output is correct
47 Correct 298 ms 1104 KB Output is correct
48 Correct 69 ms 1080 KB Output is correct
49 Correct 55 ms 864 KB Output is correct