Submission #625526

# Submission time Handle Problem Language Result Execution time Memory
625526 2022-08-10T14:23:30 Z JustInCase Stations (IOI20_stations) C++17
100 / 100
926 ms 796 KB
#include "stations.h"
#include <vector>
#include <iostream>
#include <algorithm>

#define int32_t int
#define int64_t long long

const int32_t MAX_N = 1000;

struct Vertex {
	int32_t label;
	std::vector< int32_t > v;
};

Vertex g[MAX_N + 5];

void dfs(int32_t u, int32_t &t, int32_t par, int32_t dep) {
	if(dep % 2 == 0) {
		g[u].label = t++;
	}

	for(auto &v : g[u].v) {
		if(v != par) {
			dfs(v, t, u, dep + 1);
		}
	}

	if(dep % 2 != 0) {
		g[u].label = t++;
	}
}

std::vector< int32_t > label(int32_t n, int32_t k, std::vector< int32_t > u, std::vector< int32_t > v) {
	for(int32_t i = 0; i < n; i++) {
		g[i].v.clear();
	}

	for(int32_t i = 0; i < n - 1; i++) {
		g[u[i]].v.push_back(v[i]);
		g[v[i]].v.push_back(u[i]);
	}
	
	int32_t t = 0;
	dfs(0, t, -1, 0);
	
	std::vector< int32_t > labels(n);
	for(int32_t i = 0; i < n; i++) {
		labels[i] = g[i].label;
	}

	return labels;
}

int32_t find_next_station(int32_t s, int32_t t, std::vector< int32_t > c) {
	if(s < c[0]) {
		if(t > c[c.size() - 2]) {
			return c[c.size() - 1];
		}
		if(t < s) {
			return c[c.size() - 1];
		}
		else {
			return *std::lower_bound(c.begin(), c.end(), t);
		}
	}
	else {
		if(t <= c[0]) {
			return c[0];
		}
		else if(t > s) {
			return c[0];
		}
		else {
			return *--std::upper_bound(c.begin(), c.end(), t);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 495 ms 664 KB Output is correct
2 Correct 399 ms 656 KB Output is correct
3 Correct 926 ms 416 KB Output is correct
4 Correct 600 ms 536 KB Output is correct
5 Correct 612 ms 536 KB Output is correct
6 Correct 465 ms 648 KB Output is correct
7 Correct 455 ms 544 KB Output is correct
8 Correct 2 ms 488 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 524 KB Output is correct
2 Correct 549 ms 540 KB Output is correct
3 Correct 809 ms 712 KB Output is correct
4 Correct 564 ms 772 KB Output is correct
5 Correct 585 ms 672 KB Output is correct
6 Correct 498 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 479 ms 656 KB Output is correct
2 Correct 447 ms 656 KB Output is correct
3 Correct 851 ms 420 KB Output is correct
4 Correct 583 ms 416 KB Output is correct
5 Correct 532 ms 536 KB Output is correct
6 Correct 413 ms 640 KB Output is correct
7 Correct 424 ms 540 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 628 KB Output is correct
10 Correct 1 ms 500 KB Output is correct
11 Correct 463 ms 420 KB Output is correct
12 Correct 436 ms 644 KB Output is correct
13 Correct 436 ms 676 KB Output is correct
14 Correct 463 ms 540 KB Output is correct
15 Correct 52 ms 572 KB Output is correct
16 Correct 63 ms 536 KB Output is correct
17 Correct 106 ms 660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 883 ms 612 KB Output is correct
2 Correct 600 ms 416 KB Output is correct
3 Correct 561 ms 416 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 546 ms 536 KB Output is correct
8 Correct 717 ms 416 KB Output is correct
9 Correct 578 ms 416 KB Output is correct
10 Correct 541 ms 420 KB Output is correct
11 Correct 6 ms 492 KB Output is correct
12 Correct 4 ms 492 KB Output is correct
13 Correct 5 ms 620 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 1 ms 500 KB Output is correct
16 Correct 449 ms 416 KB Output is correct
17 Correct 524 ms 612 KB Output is correct
18 Correct 402 ms 520 KB Output is correct
19 Correct 488 ms 644 KB Output is correct
20 Correct 391 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 676 KB Output is correct
2 Correct 455 ms 548 KB Output is correct
3 Correct 799 ms 416 KB Output is correct
4 Correct 674 ms 540 KB Output is correct
5 Correct 616 ms 416 KB Output is correct
6 Correct 414 ms 524 KB Output is correct
7 Correct 503 ms 516 KB Output is correct
8 Correct 4 ms 500 KB Output is correct
9 Correct 5 ms 516 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 515 ms 720 KB Output is correct
12 Correct 505 ms 640 KB Output is correct
13 Correct 878 ms 420 KB Output is correct
14 Correct 580 ms 732 KB Output is correct
15 Correct 553 ms 416 KB Output is correct
16 Correct 405 ms 660 KB Output is correct
17 Correct 545 ms 672 KB Output is correct
18 Correct 418 ms 644 KB Output is correct
19 Correct 431 ms 764 KB Output is correct
20 Correct 419 ms 540 KB Output is correct
21 Correct 53 ms 592 KB Output is correct
22 Correct 67 ms 664 KB Output is correct
23 Correct 87 ms 724 KB Output is correct
24 Correct 2 ms 752 KB Output is correct
25 Correct 4 ms 628 KB Output is correct
26 Correct 3 ms 496 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
28 Correct 1 ms 684 KB Output is correct
29 Correct 482 ms 536 KB Output is correct
30 Correct 414 ms 544 KB Output is correct
31 Correct 450 ms 796 KB Output is correct
32 Correct 525 ms 544 KB Output is correct
33 Correct 504 ms 660 KB Output is correct
34 Correct 239 ms 544 KB Output is correct
35 Correct 417 ms 772 KB Output is correct
36 Correct 460 ms 540 KB Output is correct
37 Correct 452 ms 724 KB Output is correct
38 Correct 385 ms 644 KB Output is correct
39 Correct 478 ms 756 KB Output is correct
40 Correct 447 ms 644 KB Output is correct
41 Correct 451 ms 652 KB Output is correct
42 Correct 55 ms 728 KB Output is correct
43 Correct 85 ms 752 KB Output is correct
44 Correct 137 ms 548 KB Output is correct
45 Correct 136 ms 712 KB Output is correct
46 Correct 301 ms 672 KB Output is correct
47 Correct 276 ms 628 KB Output is correct
48 Correct 51 ms 672 KB Output is correct
49 Correct 51 ms 756 KB Output is correct