답안 #1051493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1051493 2024-08-10T07:33:10 Z aykhn 기지국 (IOI20_stations) C++17
100 / 100
565 ms 1288 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 282 ms 944 KB Output is correct
2 Correct 248 ms 940 KB Output is correct
3 Correct 483 ms 684 KB Output is correct
4 Correct 371 ms 684 KB Output is correct
5 Correct 316 ms 684 KB Output is correct
6 Correct 267 ms 940 KB Output is correct
7 Correct 215 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 684 KB Output is correct
2 Correct 231 ms 792 KB Output is correct
3 Correct 406 ms 800 KB Output is correct
4 Correct 309 ms 684 KB Output is correct
5 Correct 277 ms 684 KB Output is correct
6 Correct 222 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 270 ms 940 KB Output is correct
2 Correct 250 ms 1052 KB Output is correct
3 Correct 444 ms 796 KB Output is correct
4 Correct 366 ms 684 KB Output is correct
5 Correct 337 ms 684 KB Output is correct
6 Correct 240 ms 940 KB Output is correct
7 Correct 242 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 772 KB Output is correct
10 Correct 1 ms 776 KB Output is correct
11 Correct 318 ms 684 KB Output is correct
12 Correct 254 ms 1044 KB Output is correct
13 Correct 256 ms 1052 KB Output is correct
14 Correct 284 ms 684 KB Output is correct
15 Correct 20 ms 768 KB Output is correct
16 Correct 38 ms 768 KB Output is correct
17 Correct 50 ms 688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 527 ms 684 KB Output is correct
2 Correct 374 ms 688 KB Output is correct
3 Correct 337 ms 684 KB Output is correct
4 Correct 1 ms 776 KB Output is correct
5 Correct 1 ms 776 KB Output is correct
6 Correct 0 ms 776 KB Output is correct
7 Correct 340 ms 796 KB Output is correct
8 Correct 520 ms 684 KB Output is correct
9 Correct 396 ms 684 KB Output is correct
10 Correct 299 ms 688 KB Output is correct
11 Correct 2 ms 776 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 1 ms 776 KB Output is correct
16 Correct 275 ms 792 KB Output is correct
17 Correct 279 ms 684 KB Output is correct
18 Correct 311 ms 684 KB Output is correct
19 Correct 283 ms 684 KB Output is correct
20 Correct 287 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 940 KB Output is correct
2 Correct 256 ms 940 KB Output is correct
3 Correct 529 ms 684 KB Output is correct
4 Correct 414 ms 684 KB Output is correct
5 Correct 378 ms 684 KB Output is correct
6 Correct 260 ms 940 KB Output is correct
7 Correct 242 ms 684 KB Output is correct
8 Correct 0 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 255 ms 792 KB Output is correct
12 Correct 310 ms 684 KB Output is correct
13 Correct 565 ms 684 KB Output is correct
14 Correct 352 ms 684 KB Output is correct
15 Correct 358 ms 684 KB Output is correct
16 Correct 246 ms 684 KB Output is correct
17 Correct 330 ms 944 KB Output is correct
18 Correct 261 ms 1044 KB Output is correct
19 Correct 249 ms 1040 KB Output is correct
20 Correct 242 ms 684 KB Output is correct
21 Correct 26 ms 764 KB Output is correct
22 Correct 29 ms 768 KB Output is correct
23 Correct 37 ms 764 KB Output is correct
24 Correct 2 ms 844 KB Output is correct
25 Correct 1 ms 776 KB Output is correct
26 Correct 1 ms 768 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 310 ms 684 KB Output is correct
30 Correct 303 ms 684 KB Output is correct
31 Correct 313 ms 684 KB Output is correct
32 Correct 276 ms 684 KB Output is correct
33 Correct 288 ms 684 KB Output is correct
34 Correct 163 ms 940 KB Output is correct
35 Correct 246 ms 940 KB Output is correct
36 Correct 279 ms 940 KB Output is correct
37 Correct 249 ms 804 KB Output is correct
38 Correct 242 ms 684 KB Output is correct
39 Correct 268 ms 808 KB Output is correct
40 Correct 242 ms 932 KB Output is correct
41 Correct 288 ms 796 KB Output is correct
42 Correct 39 ms 768 KB Output is correct
43 Correct 45 ms 764 KB Output is correct
44 Correct 67 ms 684 KB Output is correct
45 Correct 92 ms 760 KB Output is correct
46 Correct 164 ms 724 KB Output is correct
47 Correct 144 ms 716 KB Output is correct
48 Correct 35 ms 764 KB Output is correct
49 Correct 26 ms 1288 KB Output is correct