답안 #977360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977360 2024-05-07T19:21:47 Z aykhn 기지국 (IOI20_stations) C++17
100 / 100
632 ms 1964 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

const int MXN = 1e3 + 5;

int in[MXN], out[MXN], tim = -1;
vector<int> adj[MXN];
vector<int> labels;

void dfs(int a, int p, int w)
{
	in[a] = ++tim;
	for (int v : adj[a])
	{
		if (v == p) continue;
		dfs(v, a, w ^ 1);
	}
	out[a] = ++tim;
	if (w) labels[a] = in[a];
	else labels[a] = out[a];
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) 
{
	tim = -1;
	for (int i = 0; i < n; i++)
	{
		in[i] = out[i] = 0;
		adj[i].clear();
	}
	for (int i = 0; i < n - 1; i++) adj[u[i]].push_back(v[i]), adj[v[i]].push_back(u[i]);
	labels.assign(n, 0);
	dfs(0, 0, 0);
	vector<array<int, 2>> v1;
	for (int i = 0; i < labels.size(); i++) v1.push_back({labels[i], i});
	sort(v1.begin(), v1.end());
	for (int i = 0; i < v1.size(); i++) labels[v1[i][1]] = i;
	return labels;
}

int find_next_station(int s, int t, vector<int> c)
{
	for (int x : c) if (x == t) return t;
	int sz = c.size();
	if (sz == 1) return c[0];
	else if (s < c[0])
	{
		if (!(s <= t && t <= c[sz - 2])) return c[sz - 1];
		c.pop_back();
		for (int x : c) if (t <= x) return x;
	}
	else
	{
		if (!(c[1] <= t && t <= s)) return c[0];
		c.erase(c.begin());
		reverse(c.begin(), c.end());
		for (int x : c) if (x <= t) return x;
	}
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for (int i = 0; i < labels.size(); i++) v1.push_back({labels[i], i});
      |                  ~~^~~~~~~~~~~~~~~
stations.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for (int i = 0; i < v1.size(); i++) labels[v1[i][1]] = i;
      |                  ~~^~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 944 KB Output is correct
2 Correct 294 ms 948 KB Output is correct
3 Correct 536 ms 684 KB Output is correct
4 Correct 452 ms 684 KB Output is correct
5 Correct 378 ms 684 KB Output is correct
6 Correct 300 ms 932 KB Output is correct
7 Correct 279 ms 688 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 888 KB Output is correct
2 Correct 348 ms 816 KB Output is correct
3 Correct 540 ms 684 KB Output is correct
4 Correct 436 ms 684 KB Output is correct
5 Correct 379 ms 936 KB Output is correct
6 Correct 264 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 956 KB Output is correct
2 Correct 259 ms 952 KB Output is correct
3 Correct 507 ms 940 KB Output is correct
4 Correct 388 ms 796 KB Output is correct
5 Correct 366 ms 792 KB Output is correct
6 Correct 259 ms 924 KB Output is correct
7 Correct 266 ms 940 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 366 ms 940 KB Output is correct
12 Correct 303 ms 992 KB Output is correct
13 Correct 293 ms 1328 KB Output is correct
14 Correct 300 ms 684 KB Output is correct
15 Correct 40 ms 764 KB Output is correct
16 Correct 39 ms 860 KB Output is correct
17 Correct 57 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 552 ms 684 KB Output is correct
2 Correct 394 ms 684 KB Output is correct
3 Correct 376 ms 684 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 3 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 398 ms 684 KB Output is correct
8 Correct 578 ms 684 KB Output is correct
9 Correct 439 ms 684 KB Output is correct
10 Correct 348 ms 684 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 336 ms 684 KB Output is correct
17 Correct 316 ms 684 KB Output is correct
18 Correct 314 ms 684 KB Output is correct
19 Correct 357 ms 684 KB Output is correct
20 Correct 328 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 948 KB Output is correct
2 Correct 292 ms 944 KB Output is correct
3 Correct 582 ms 684 KB Output is correct
4 Correct 475 ms 684 KB Output is correct
5 Correct 366 ms 684 KB Output is correct
6 Correct 289 ms 952 KB Output is correct
7 Correct 266 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 1020 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 299 ms 888 KB Output is correct
12 Correct 346 ms 852 KB Output is correct
13 Correct 632 ms 684 KB Output is correct
14 Correct 398 ms 684 KB Output is correct
15 Correct 394 ms 684 KB Output is correct
16 Correct 308 ms 684 KB Output is correct
17 Correct 328 ms 944 KB Output is correct
18 Correct 306 ms 1040 KB Output is correct
19 Correct 330 ms 1312 KB Output is correct
20 Correct 287 ms 684 KB Output is correct
21 Correct 34 ms 808 KB Output is correct
22 Correct 43 ms 884 KB Output is correct
23 Correct 63 ms 884 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 764 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 3 ms 768 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 306 ms 684 KB Output is correct
30 Correct 319 ms 936 KB Output is correct
31 Correct 320 ms 684 KB Output is correct
32 Correct 302 ms 684 KB Output is correct
33 Correct 317 ms 684 KB Output is correct
34 Correct 203 ms 932 KB Output is correct
35 Correct 271 ms 1324 KB Output is correct
36 Correct 291 ms 1128 KB Output is correct
37 Correct 277 ms 1168 KB Output is correct
38 Correct 279 ms 1020 KB Output is correct
39 Correct 252 ms 1164 KB Output is correct
40 Correct 291 ms 1180 KB Output is correct
41 Correct 300 ms 1288 KB Output is correct
42 Correct 38 ms 956 KB Output is correct
43 Correct 53 ms 960 KB Output is correct
44 Correct 95 ms 948 KB Output is correct
45 Correct 88 ms 924 KB Output is correct
46 Correct 218 ms 884 KB Output is correct
47 Correct 189 ms 908 KB Output is correct
48 Correct 33 ms 1452 KB Output is correct
49 Correct 34 ms 1964 KB Output is correct