답안 #851688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851688 2023-09-20T11:27:48 Z yellowtoad 기지국 (IOI20_stations) C++17
100 / 100
594 ms 1680 KB
#include "stations.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> path, edge[1010];

void dfs(int u, int v, int d) {
	if (d%2 == 0) path.push_back(u);
	for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs(edge[u][i],u,d+1);
	if (d%2) path.push_back(u);
}

std::vector<int> label(int n, int _, std::vector<int> u, std::vector<int> v) {
	path.clear();
	vector<int> labels(n);
	for (int i = 0; i < n; i++) edge[i].clear();
	for (int i = 0; i < n-1; i++) {
		edge[u[i]].push_back(v[i]);
		edge[v[i]].push_back(u[i]);
	}
	dfs(0,-1,0);
	for (int i = 0; i < n; i++) labels[path[i]] = i;
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if (c[0] > s) {
		if (t < s) return c[c.size()-1];
		for (int i = 0; i < c.size()-1; i++) if (t <= c[i]) return c[i];
		return c[c.size()-1];
	} else {
		if (t > s) return c[0]; 
		for (int i = c.size()-1; i >= 1; i--) if (t >= c[i]) return c[i];
		return c[0];
	}
}

Compilation message

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for (int i = 0; i < edge[u].size(); i++) if (edge[u][i] != v) dfs(edge[u][i],u,d+1);
      |                  ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i = 0; i < c.size()-1; i++) if (t <= c[i]) return c[i];
      |                   ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 920 KB Output is correct
2 Correct 312 ms 928 KB Output is correct
3 Correct 553 ms 684 KB Output is correct
4 Correct 446 ms 684 KB Output is correct
5 Correct 365 ms 684 KB Output is correct
6 Correct 289 ms 1164 KB Output is correct
7 Correct 242 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 311 ms 872 KB Output is correct
2 Correct 322 ms 808 KB Output is correct
3 Correct 594 ms 684 KB Output is correct
4 Correct 414 ms 684 KB Output is correct
5 Correct 361 ms 712 KB Output is correct
6 Correct 263 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 920 KB Output is correct
2 Correct 329 ms 928 KB Output is correct
3 Correct 560 ms 684 KB Output is correct
4 Correct 450 ms 684 KB Output is correct
5 Correct 361 ms 684 KB Output is correct
6 Correct 313 ms 900 KB Output is correct
7 Correct 310 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 428 ms 684 KB Output is correct
12 Correct 315 ms 1228 KB Output is correct
13 Correct 308 ms 1016 KB Output is correct
14 Correct 287 ms 684 KB Output is correct
15 Correct 34 ms 764 KB Output is correct
16 Correct 46 ms 848 KB Output is correct
17 Correct 70 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 542 ms 684 KB Output is correct
2 Correct 439 ms 684 KB Output is correct
3 Correct 399 ms 688 KB Output is correct
4 Correct 2 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 365 ms 684 KB Output is correct
8 Correct 574 ms 684 KB Output is correct
9 Correct 435 ms 684 KB Output is correct
10 Correct 393 ms 684 KB Output is correct
11 Correct 4 ms 764 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 764 KB Output is correct
15 Correct 1 ms 764 KB Output is correct
16 Correct 359 ms 684 KB Output is correct
17 Correct 349 ms 684 KB Output is correct
18 Correct 340 ms 688 KB Output is correct
19 Correct 330 ms 684 KB Output is correct
20 Correct 358 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 367 ms 912 KB Output is correct
2 Correct 319 ms 916 KB Output is correct
3 Correct 541 ms 684 KB Output is correct
4 Correct 490 ms 684 KB Output is correct
5 Correct 374 ms 684 KB Output is correct
6 Correct 275 ms 920 KB Output is correct
7 Correct 281 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 323 ms 872 KB Output is correct
12 Correct 343 ms 1096 KB Output is correct
13 Correct 590 ms 684 KB Output is correct
14 Correct 422 ms 856 KB Output is correct
15 Correct 356 ms 684 KB Output is correct
16 Correct 292 ms 684 KB Output is correct
17 Correct 413 ms 684 KB Output is correct
18 Correct 296 ms 1252 KB Output is correct
19 Correct 326 ms 1476 KB Output is correct
20 Correct 286 ms 684 KB Output is correct
21 Correct 32 ms 764 KB Output is correct
22 Correct 41 ms 924 KB Output is correct
23 Correct 66 ms 856 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 3 ms 764 KB Output is correct
26 Correct 2 ms 760 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 0 ms 764 KB Output is correct
29 Correct 350 ms 864 KB Output is correct
30 Correct 324 ms 684 KB Output is correct
31 Correct 327 ms 684 KB Output is correct
32 Correct 325 ms 684 KB Output is correct
33 Correct 288 ms 684 KB Output is correct
34 Correct 183 ms 900 KB Output is correct
35 Correct 265 ms 1644 KB Output is correct
36 Correct 303 ms 1268 KB Output is correct
37 Correct 290 ms 1256 KB Output is correct
38 Correct 264 ms 1156 KB Output is correct
39 Correct 284 ms 1020 KB Output is correct
40 Correct 284 ms 1000 KB Output is correct
41 Correct 295 ms 1248 KB Output is correct
42 Correct 38 ms 860 KB Output is correct
43 Correct 64 ms 948 KB Output is correct
44 Correct 86 ms 884 KB Output is correct
45 Correct 90 ms 892 KB Output is correct
46 Correct 185 ms 860 KB Output is correct
47 Correct 212 ms 888 KB Output is correct
48 Correct 37 ms 1164 KB Output is correct
49 Correct 37 ms 1680 KB Output is correct