Submission #312001

# Submission time Handle Problem Language Result Execution time Memory
312001 2020-10-12T06:17:47 Z natsugirl Stations (IOI20_stations) C++17
100 / 100
1011 ms 1052 KB
/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); i++)
#define cont(i, n)          for(int i = 1; i <= (n); i++)
#define circ(i, a, b)       for(int i = (a); i <= (b); i++)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

#include "stations.h"

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<vector<int> > nei(n);
	loop(i, n - 1) nei[u[i]].pub(v[i]), nei[v[i]].pub(u[i]);
	vector<int> res(n);
	int tmc = 0;
	function<void(int, int, int)> dfs = [&](int now, int lst, int lvl) {
		if(lvl == 0) res[now] = ++tmc;
		loop(i, SZ(nei[now])) {
			int to = nei[now][i];
			if(to == lst) continue;
			dfs(to, now, lvl ^ 1);
		}
		if(lvl == 1) res[now] = ++tmc;
	};
	dfs(0, -1, 0);
	return res;
}

int find_next_station(int s, int t, vector<int> c) {
	vector<int> cs = c;
	int fa;
	sort(all(cs));
	if(cs[0] > s) fa = cs.back(), cs.pob(), cs.insert(cs.begin(), s);
	else fa = cs[0], cs.erase(cs.begin()), cs.pub(s);
	loop(i, SZ(cs)) if(cs[i] == t) return t;
	loop(i, SZ(cs) - 1) {
		int l = cs[i], r = cs[i + 1];
		if(t >= l && t <= r) {
			if(cs[0] == s) return r;
			else return l;
		}
	}
	return fa;
}
# Verdict Execution time Memory Grader output
1 Correct 699 ms 1024 KB Output is correct
2 Correct 538 ms 1024 KB Output is correct
3 Correct 1011 ms 648 KB Output is correct
4 Correct 690 ms 640 KB Output is correct
5 Correct 677 ms 648 KB Output is correct
6 Correct 453 ms 1024 KB Output is correct
7 Correct 440 ms 1024 KB Output is correct
8 Correct 3 ms 652 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 964 KB Output is correct
2 Correct 597 ms 768 KB Output is correct
3 Correct 885 ms 800 KB Output is correct
4 Correct 816 ms 652 KB Output is correct
5 Correct 614 ms 640 KB Output is correct
6 Correct 457 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 1024 KB Output is correct
2 Correct 457 ms 1008 KB Output is correct
3 Correct 884 ms 760 KB Output is correct
4 Correct 647 ms 640 KB Output is correct
5 Correct 570 ms 660 KB Output is correct
6 Correct 458 ms 1024 KB Output is correct
7 Correct 470 ms 1024 KB Output is correct
8 Correct 3 ms 800 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 1 ms 648 KB Output is correct
11 Correct 601 ms 640 KB Output is correct
12 Correct 482 ms 1024 KB Output is correct
13 Correct 456 ms 1024 KB Output is correct
14 Correct 475 ms 832 KB Output is correct
15 Correct 60 ms 640 KB Output is correct
16 Correct 72 ms 856 KB Output is correct
17 Correct 112 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 997 ms 752 KB Output is correct
2 Correct 723 ms 648 KB Output is correct
3 Correct 650 ms 648 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 655 ms 652 KB Output is correct
8 Correct 945 ms 648 KB Output is correct
9 Correct 692 ms 640 KB Output is correct
10 Correct 626 ms 640 KB Output is correct
11 Correct 5 ms 644 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 648 KB Output is correct
14 Correct 3 ms 640 KB Output is correct
15 Correct 2 ms 648 KB Output is correct
16 Correct 601 ms 768 KB Output is correct
17 Correct 612 ms 644 KB Output is correct
18 Correct 501 ms 640 KB Output is correct
19 Correct 488 ms 644 KB Output is correct
20 Correct 513 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 526 ms 1024 KB Output is correct
2 Correct 458 ms 1024 KB Output is correct
3 Correct 867 ms 644 KB Output is correct
4 Correct 654 ms 892 KB Output is correct
5 Correct 574 ms 644 KB Output is correct
6 Correct 468 ms 1024 KB Output is correct
7 Correct 475 ms 772 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 1 ms 668 KB Output is correct
11 Correct 496 ms 768 KB Output is correct
12 Correct 537 ms 820 KB Output is correct
13 Correct 897 ms 800 KB Output is correct
14 Correct 660 ms 812 KB Output is correct
15 Correct 581 ms 648 KB Output is correct
16 Correct 457 ms 832 KB Output is correct
17 Correct 598 ms 644 KB Output is correct
18 Correct 519 ms 1024 KB Output is correct
19 Correct 501 ms 1052 KB Output is correct
20 Correct 449 ms 824 KB Output is correct
21 Correct 76 ms 892 KB Output is correct
22 Correct 90 ms 856 KB Output is correct
23 Correct 123 ms 768 KB Output is correct
24 Correct 7 ms 648 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 6 ms 640 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 2 ms 644 KB Output is correct
29 Correct 618 ms 644 KB Output is correct
30 Correct 513 ms 640 KB Output is correct
31 Correct 513 ms 644 KB Output is correct
32 Correct 533 ms 644 KB Output is correct
33 Correct 519 ms 640 KB Output is correct
34 Correct 323 ms 1024 KB Output is correct
35 Correct 438 ms 1024 KB Output is correct
36 Correct 418 ms 1016 KB Output is correct
37 Correct 552 ms 804 KB Output is correct
38 Correct 613 ms 1008 KB Output is correct
39 Correct 470 ms 796 KB Output is correct
40 Correct 481 ms 780 KB Output is correct
41 Correct 569 ms 804 KB Output is correct
42 Correct 83 ms 768 KB Output is correct
43 Correct 147 ms 820 KB Output is correct
44 Correct 184 ms 836 KB Output is correct
45 Correct 179 ms 768 KB Output is correct
46 Correct 342 ms 768 KB Output is correct
47 Correct 366 ms 768 KB Output is correct
48 Correct 66 ms 768 KB Output is correct
49 Correct 59 ms 768 KB Output is correct