Submission #849359

# Submission time Handle Problem Language Result Execution time Memory
849359 2023-09-14T14:16:24 Z IBory Stations (IOI20_stations) C++17
100 / 100
554 ms 1588 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1004;
vector<int> G[MAX], ans;
int in[MAX], out[MAX], dn;

void DFS(int cur, int prev, int H) {
	in[cur] = dn++;
	for (int next : G[cur]) {
		if (next == prev) continue;
		DFS(next, cur, H + 1);
	}
	out[cur] = dn++;
	ans[cur] = ((H & 1) ? out[cur] : in[cur]);
}

vector<int> label(int N, int K, vector<int> U, vector<int> V) {
	for (int i = 0; i < N - 1; ++i) {
		G[U[i]].push_back(V[i]);
		G[V[i]].push_back(U[i]);
	}
	ans.resize(N);
	DFS(0, -1, 0);
	vector<int> T;
	for (int n : ans) T.push_back(n);
	sort(T.begin(), T.end());
	for (int& n : ans) n = lower_bound(T.begin(), T.end(), n) - T.begin();
	for (int i = 0; i < N; ++i) G[i].clear();
	dn = 0;
	return ans;
}

int find_next_station(int S, int T, vector<int> C) {
	sort(C.begin(), C.end());

	// S is in, C is out
	if (S < C[0]) {
		int pv = S;
		for (int i = 0; i + 1 < C.size(); ++i) {
			if (pv < T && T <= C[i]) return C[i];
			pv = C[i];
		}
		return C.back();
	}
	// S is out, C is in
	else {
		C.push_back(S);
		for (int i = 1; i + 1 < C.size(); ++i) {
			if (C[i] <= T && T < C[i + 1]) return C[i];
		}
		return C[0];
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:41:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (int i = 0; i + 1 < C.size(); ++i) {
      |                   ~~~~~~^~~~~~~~~~
stations.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for (int i = 1; i + 1 < C.size(); ++i) {
      |                   ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 308 ms 948 KB Output is correct
2 Correct 259 ms 944 KB Output is correct
3 Correct 533 ms 684 KB Output is correct
4 Correct 395 ms 684 KB Output is correct
5 Correct 342 ms 684 KB Output is correct
6 Correct 261 ms 928 KB Output is correct
7 Correct 269 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 1136 KB Output is correct
2 Correct 317 ms 1080 KB Output is correct
3 Correct 506 ms 684 KB Output is correct
4 Correct 407 ms 688 KB Output is correct
5 Correct 347 ms 684 KB Output is correct
6 Correct 260 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 952 KB Output is correct
2 Correct 290 ms 944 KB Output is correct
3 Correct 539 ms 940 KB Output is correct
4 Correct 378 ms 684 KB Output is correct
5 Correct 357 ms 684 KB Output is correct
6 Correct 259 ms 928 KB Output is correct
7 Correct 263 ms 684 KB Output is correct
8 Correct 1 ms 772 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 327 ms 684 KB Output is correct
12 Correct 268 ms 1456 KB Output is correct
13 Correct 239 ms 1300 KB Output is correct
14 Correct 267 ms 684 KB Output is correct
15 Correct 28 ms 768 KB Output is correct
16 Correct 34 ms 888 KB Output is correct
17 Correct 59 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 684 KB Output is correct
2 Correct 394 ms 852 KB Output is correct
3 Correct 355 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 1 ms 772 KB Output is correct
7 Correct 344 ms 684 KB Output is correct
8 Correct 554 ms 684 KB Output is correct
9 Correct 411 ms 684 KB Output is correct
10 Correct 405 ms 684 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 768 KB Output is correct
16 Correct 314 ms 684 KB Output is correct
17 Correct 284 ms 684 KB Output is correct
18 Correct 293 ms 940 KB Output is correct
19 Correct 291 ms 684 KB Output is correct
20 Correct 282 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 944 KB Output is correct
2 Correct 266 ms 948 KB Output is correct
3 Correct 548 ms 684 KB Output is correct
4 Correct 389 ms 684 KB Output is correct
5 Correct 381 ms 684 KB Output is correct
6 Correct 279 ms 948 KB Output is correct
7 Correct 258 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 772 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 259 ms 876 KB Output is correct
12 Correct 290 ms 852 KB Output is correct
13 Correct 543 ms 684 KB Output is correct
14 Correct 390 ms 684 KB Output is correct
15 Correct 356 ms 684 KB Output is correct
16 Correct 312 ms 936 KB Output is correct
17 Correct 409 ms 684 KB Output is correct
18 Correct 270 ms 1172 KB Output is correct
19 Correct 290 ms 1312 KB Output is correct
20 Correct 268 ms 684 KB Output is correct
21 Correct 33 ms 768 KB Output is correct
22 Correct 38 ms 936 KB Output is correct
23 Correct 57 ms 1140 KB Output is correct
24 Correct 3 ms 764 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 1 ms 764 KB Output is correct
29 Correct 323 ms 688 KB Output is correct
30 Correct 320 ms 684 KB Output is correct
31 Correct 338 ms 684 KB Output is correct
32 Correct 331 ms 684 KB Output is correct
33 Correct 310 ms 684 KB Output is correct
34 Correct 202 ms 920 KB Output is correct
35 Correct 284 ms 1324 KB Output is correct
36 Correct 294 ms 1188 KB Output is correct
37 Correct 272 ms 1024 KB Output is correct
38 Correct 303 ms 1280 KB Output is correct
39 Correct 288 ms 1048 KB Output is correct
40 Correct 341 ms 1416 KB Output is correct
41 Correct 282 ms 1268 KB Output is correct
42 Correct 35 ms 904 KB Output is correct
43 Correct 61 ms 1200 KB Output is correct
44 Correct 90 ms 960 KB Output is correct
45 Correct 99 ms 904 KB Output is correct
46 Correct 236 ms 876 KB Output is correct
47 Correct 202 ms 900 KB Output is correct
48 Correct 37 ms 1436 KB Output is correct
49 Correct 39 ms 1588 KB Output is correct