Submission #744670

# Submission time Handle Problem Language Result Execution time Memory
744670 2023-05-18T23:23:32 Z GusterGoose27 Stations (IOI20_stations) C++17
100 / 100
1035 ms 820 KB
#include "stations.h"

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000;

vector<int> edges[MAXN];
int t = 0;

void dfs(int cur, bool par, int p, vector<int> &ans) {
	if (par) ans[cur] = t++;
	for (int nxt: edges[cur]) {
		if (nxt == p) continue;
		dfs(nxt, !par, cur, ans);
	}
	if (!par) ans[cur] = t++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	t = 0;
	for (int i = 0; i < n; i++) edges[i].clear();
	vector<int> ans(n);
	for (int i = 0; i < n-1; i++) {
		edges[u[i]].push_back(v[i]);
		edges[v[i]].push_back(u[i]);
	}
	dfs(0, 1, -1, ans);
	return ans;
}

int find_next_station(int s, int t, vector<int> c) {
	// return 0;
	if (c.size() == 1) return c[0];
	if (s == 0) {
		for (int i = 0; i < c.size(); i++) if (c[i] >= t) return c[i];
	}
	vector<int> vals; // left inclusive, right exclusive
	if (s < c[0]) {
		int l = s;
		int r = c[c.size()-2];
		if (t > r || t < l) return c.back();
		for (int i: c) {
			if (i >= t) return i;
		}
	}
	int l = c[1];
	int r = s;
	if (t < l || t > r) return c[0];
	for (int i = c.size()-1; i > 0; i--)
		if (c[i] <= t) return c[i];
	return 0;
	assert(false);
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:37:21: 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 < c.size(); i++) if (c[i] >= t) return c[i];
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 668 ms 716 KB Output is correct
2 Correct 438 ms 756 KB Output is correct
3 Correct 868 ms 416 KB Output is correct
4 Correct 897 ms 416 KB Output is correct
5 Correct 638 ms 416 KB Output is correct
6 Correct 465 ms 640 KB Output is correct
7 Correct 534 ms 548 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 5 ms 592 KB Output is correct
10 Correct 1 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 528 KB Output is correct
2 Correct 586 ms 580 KB Output is correct
3 Correct 969 ms 512 KB Output is correct
4 Correct 737 ms 532 KB Output is correct
5 Correct 473 ms 572 KB Output is correct
6 Correct 444 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 548 KB Output is correct
2 Correct 461 ms 672 KB Output is correct
3 Correct 1035 ms 416 KB Output is correct
4 Correct 644 ms 508 KB Output is correct
5 Correct 651 ms 416 KB Output is correct
6 Correct 504 ms 716 KB Output is correct
7 Correct 521 ms 600 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 5 ms 500 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 752 ms 532 KB Output is correct
12 Correct 471 ms 684 KB Output is correct
13 Correct 549 ms 752 KB Output is correct
14 Correct 511 ms 544 KB Output is correct
15 Correct 58 ms 432 KB Output is correct
16 Correct 62 ms 544 KB Output is correct
17 Correct 119 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 891 ms 416 KB Output is correct
2 Correct 802 ms 596 KB Output is correct
3 Correct 717 ms 532 KB Output is correct
4 Correct 4 ms 444 KB Output is correct
5 Correct 5 ms 440 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 691 ms 508 KB Output is correct
8 Correct 998 ms 524 KB Output is correct
9 Correct 688 ms 416 KB Output is correct
10 Correct 723 ms 480 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 5 ms 496 KB Output is correct
13 Correct 4 ms 492 KB Output is correct
14 Correct 4 ms 500 KB Output is correct
15 Correct 2 ms 500 KB Output is correct
16 Correct 514 ms 472 KB Output is correct
17 Correct 644 ms 544 KB Output is correct
18 Correct 546 ms 416 KB Output is correct
19 Correct 584 ms 524 KB Output is correct
20 Correct 495 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 618 ms 652 KB Output is correct
2 Correct 581 ms 524 KB Output is correct
3 Correct 954 ms 444 KB Output is correct
4 Correct 686 ms 508 KB Output is correct
5 Correct 686 ms 528 KB Output is correct
6 Correct 434 ms 548 KB Output is correct
7 Correct 463 ms 528 KB Output is correct
8 Correct 3 ms 496 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 458 ms 592 KB Output is correct
12 Correct 527 ms 524 KB Output is correct
13 Correct 771 ms 416 KB Output is correct
14 Correct 632 ms 420 KB Output is correct
15 Correct 591 ms 524 KB Output is correct
16 Correct 451 ms 536 KB Output is correct
17 Correct 487 ms 528 KB Output is correct
18 Correct 357 ms 528 KB Output is correct
19 Correct 451 ms 760 KB Output is correct
20 Correct 397 ms 544 KB Output is correct
21 Correct 56 ms 444 KB Output is correct
22 Correct 58 ms 572 KB Output is correct
23 Correct 109 ms 560 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 4 ms 500 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 553 ms 416 KB Output is correct
30 Correct 523 ms 420 KB Output is correct
31 Correct 484 ms 416 KB Output is correct
32 Correct 534 ms 416 KB Output is correct
33 Correct 480 ms 528 KB Output is correct
34 Correct 287 ms 548 KB Output is correct
35 Correct 379 ms 672 KB Output is correct
36 Correct 489 ms 652 KB Output is correct
37 Correct 457 ms 636 KB Output is correct
38 Correct 437 ms 700 KB Output is correct
39 Correct 471 ms 644 KB Output is correct
40 Correct 392 ms 768 KB Output is correct
41 Correct 502 ms 656 KB Output is correct
42 Correct 66 ms 676 KB Output is correct
43 Correct 102 ms 572 KB Output is correct
44 Correct 147 ms 544 KB Output is correct
45 Correct 190 ms 528 KB Output is correct
46 Correct 271 ms 524 KB Output is correct
47 Correct 279 ms 528 KB Output is correct
48 Correct 66 ms 676 KB Output is correct
49 Correct 68 ms 820 KB Output is correct