Submission #1033197

# Submission time Handle Problem Language Result Execution time Memory
1033197 2024-07-24T14:05:29 Z thinknoexit Stations (IOI20_stations) C++17
100 / 100
636 ms 1296 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> adj[1010];
int res[1010], sz[1010], lv[1010];
void dfs_sz(int v, int p = -1) {
	sz[v] = 1;
	for (auto& x : adj[v]) {
		if (x == p) continue;
		lv[x] = lv[v] ^ 1;
		dfs_sz(x, v);
		sz[v] += sz[x];
	}
}
void dfs(int v, int l, int r, int p = -1) {
	if (lv[v] & 1) res[v] = r--;
	else res[v] = l++;
	for (auto& x : adj[v]) {
		if (x == p) continue;
		if (lv[v] & 1) {
			dfs(x, l, l + sz[x] - 1, v);
			l += sz[x];
		}
		else {
			dfs(x, r - sz[x] + 1, r, v);
			r -= sz[x];
		}
	}

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

int find_next_station(int s, int t, vector<int> c) {
	int k = c.size();
	if (k == 1) return c[0];
	bool ch = 1;
	for (auto& x : c) ch &= s < x;
	if (ch) { // is minimum of subtree
		sort(c.rbegin(), c.rend());
		if (s != 1 && (t < s || t > c[0])) return c[0];
		int ans = 0;
		for (auto& x : c) {
			if (t <= x) ans = x;
		}
		return ans;
	}
	else { // is maximum of subtree
		sort(c.begin(), c.end());
		if (t > s || t < c[1]) return c[0];
		int ans = 0;
		for (auto& x : c) {
			if (t >= x) ans = x;
		}
		return ans;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 368 ms 940 KB Output is correct
2 Correct 304 ms 1192 KB Output is correct
3 Correct 603 ms 684 KB Output is correct
4 Correct 450 ms 684 KB Output is correct
5 Correct 386 ms 684 KB Output is correct
6 Correct 315 ms 684 KB Output is correct
7 Correct 326 ms 684 KB Output is correct
8 Correct 1 ms 776 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 688 KB Output is correct
2 Correct 333 ms 688 KB Output is correct
3 Correct 601 ms 684 KB Output is correct
4 Correct 440 ms 684 KB Output is correct
5 Correct 416 ms 684 KB Output is correct
6 Correct 321 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 340 ms 940 KB Output is correct
2 Correct 280 ms 940 KB Output is correct
3 Correct 636 ms 684 KB Output is correct
4 Correct 463 ms 684 KB Output is correct
5 Correct 376 ms 684 KB Output is correct
6 Correct 293 ms 684 KB Output is correct
7 Correct 277 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 764 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 373 ms 684 KB Output is correct
12 Correct 306 ms 1044 KB Output is correct
13 Correct 335 ms 1296 KB Output is correct
14 Correct 290 ms 684 KB Output is correct
15 Correct 34 ms 736 KB Output is correct
16 Correct 40 ms 768 KB Output is correct
17 Correct 57 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 586 ms 684 KB Output is correct
2 Correct 369 ms 684 KB Output is correct
3 Correct 403 ms 688 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 776 KB Output is correct
7 Correct 375 ms 684 KB Output is correct
8 Correct 609 ms 684 KB Output is correct
9 Correct 466 ms 684 KB Output is correct
10 Correct 368 ms 684 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 2 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 1 ms 764 KB Output is correct
15 Correct 1 ms 760 KB Output is correct
16 Correct 316 ms 684 KB Output is correct
17 Correct 377 ms 688 KB Output is correct
18 Correct 345 ms 684 KB Output is correct
19 Correct 293 ms 940 KB Output is correct
20 Correct 329 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 940 KB Output is correct
2 Correct 258 ms 684 KB Output is correct
3 Correct 489 ms 684 KB Output is correct
4 Correct 404 ms 684 KB Output is correct
5 Correct 350 ms 944 KB Output is correct
6 Correct 287 ms 940 KB Output is correct
7 Correct 272 ms 684 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 284 ms 872 KB Output is correct
12 Correct 312 ms 684 KB Output is correct
13 Correct 539 ms 684 KB Output is correct
14 Correct 422 ms 684 KB Output is correct
15 Correct 378 ms 684 KB Output is correct
16 Correct 280 ms 684 KB Output is correct
17 Correct 337 ms 684 KB Output is correct
18 Correct 255 ms 808 KB Output is correct
19 Correct 310 ms 788 KB Output is correct
20 Correct 317 ms 684 KB Output is correct
21 Correct 38 ms 1016 KB Output is correct
22 Correct 48 ms 700 KB Output is correct
23 Correct 78 ms 684 KB Output is correct
24 Correct 3 ms 776 KB Output is correct
25 Correct 3 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 2 ms 764 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 373 ms 684 KB Output is correct
30 Correct 373 ms 684 KB Output is correct
31 Correct 348 ms 684 KB Output is correct
32 Correct 301 ms 684 KB Output is correct
33 Correct 340 ms 684 KB Output is correct
34 Correct 194 ms 684 KB Output is correct
35 Correct 305 ms 940 KB Output is correct
36 Correct 269 ms 684 KB Output is correct
37 Correct 310 ms 1040 KB Output is correct
38 Correct 292 ms 804 KB Output is correct
39 Correct 310 ms 804 KB Output is correct
40 Correct 301 ms 932 KB Output is correct
41 Correct 327 ms 1048 KB Output is correct
42 Correct 37 ms 768 KB Output is correct
43 Correct 54 ms 716 KB Output is correct
44 Correct 75 ms 684 KB Output is correct
45 Correct 93 ms 768 KB Output is correct
46 Correct 222 ms 796 KB Output is correct
47 Correct 176 ms 684 KB Output is correct
48 Correct 39 ms 992 KB Output is correct
49 Correct 34 ms 776 KB Output is correct