답안 #871214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871214 2023-11-10T09:03:20 Z abczz 기지국 (IOI20_stations) C++14
100 / 100
524 ms 1560 KB
#include "stations.h"
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

vector <ll> adj[1000];
ll sz[1000], A[1000];

void dfs(ll u, ll p) {
	++sz[u];
	for (auto v : adj[u]) {
		if (v != p) {
			dfs(v, u);
			sz[u] += sz[v];
		}
	}
}

void solve(ll u, ll p, ll l, ll r, ll d) {
	if (!d) A[u] = l++;
	else A[u] = r--;
	for (auto v : adj[u]) {
		if (v != p) {
			solve(v, u, l, l+sz[v]-1, d^1);
			l += sz[v];
		}
	}
}

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

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	ll mn = s, mx = s;
	for (auto u : c) {
		mn = min(mn, (ll)u);
		mx = max(mx, (ll)u);
	}
	if (t < mn || mx < t) {
		if (mn == s) return mx;
		else return mn;
	}
	else {
		if (mn == s) {
			auto it = lower_bound(c.begin(), c.end(), t);
			return *it;
		}
		else {
			auto it = prev(lower_bound(c.begin(), c.end(), t+1));
			return *it;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 940 KB Output is correct
2 Correct 258 ms 948 KB Output is correct
3 Correct 512 ms 684 KB Output is correct
4 Correct 373 ms 684 KB Output is correct
5 Correct 325 ms 684 KB Output is correct
6 Correct 255 ms 928 KB Output is correct
7 Correct 243 ms 688 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 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 251 ms 880 KB Output is correct
2 Correct 298 ms 816 KB Output is correct
3 Correct 518 ms 800 KB Output is correct
4 Correct 375 ms 684 KB Output is correct
5 Correct 355 ms 684 KB Output is correct
6 Correct 260 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 952 KB Output is correct
2 Correct 238 ms 1288 KB Output is correct
3 Correct 505 ms 684 KB Output is correct
4 Correct 383 ms 684 KB Output is correct
5 Correct 335 ms 940 KB Output is correct
6 Correct 265 ms 916 KB Output is correct
7 Correct 243 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 1024 KB Output is correct
10 Correct 0 ms 1024 KB Output is correct
11 Correct 350 ms 940 KB Output is correct
12 Correct 270 ms 984 KB Output is correct
13 Correct 298 ms 1308 KB Output is correct
14 Correct 252 ms 684 KB Output is correct
15 Correct 26 ms 1016 KB Output is correct
16 Correct 39 ms 884 KB Output is correct
17 Correct 60 ms 880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 684 KB Output is correct
2 Correct 424 ms 684 KB Output is correct
3 Correct 345 ms 944 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 1 ms 764 KB Output is correct
7 Correct 318 ms 800 KB Output is correct
8 Correct 515 ms 688 KB Output is correct
9 Correct 383 ms 684 KB Output is correct
10 Correct 360 ms 684 KB Output is correct
11 Correct 4 ms 764 KB Output is correct
12 Correct 6 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 0 ms 764 KB Output is correct
16 Correct 280 ms 688 KB Output is correct
17 Correct 292 ms 684 KB Output is correct
18 Correct 301 ms 684 KB Output is correct
19 Correct 274 ms 684 KB Output is correct
20 Correct 294 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 936 KB Output is correct
2 Correct 249 ms 940 KB Output is correct
3 Correct 495 ms 684 KB Output is correct
4 Correct 337 ms 684 KB Output is correct
5 Correct 306 ms 684 KB Output is correct
6 Correct 244 ms 1156 KB Output is correct
7 Correct 271 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 764 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 243 ms 888 KB Output is correct
12 Correct 312 ms 852 KB Output is correct
13 Correct 524 ms 684 KB Output is correct
14 Correct 380 ms 936 KB Output is correct
15 Correct 338 ms 936 KB Output is correct
16 Correct 248 ms 684 KB Output is correct
17 Correct 335 ms 684 KB Output is correct
18 Correct 267 ms 1280 KB Output is correct
19 Correct 282 ms 1316 KB Output is correct
20 Correct 245 ms 680 KB Output is correct
21 Correct 31 ms 768 KB Output is correct
22 Correct 38 ms 1192 KB Output is correct
23 Correct 59 ms 912 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 0 ms 768 KB Output is correct
29 Correct 301 ms 940 KB Output is correct
30 Correct 270 ms 684 KB Output is correct
31 Correct 268 ms 684 KB Output is correct
32 Correct 277 ms 684 KB Output is correct
33 Correct 306 ms 684 KB Output is correct
34 Correct 177 ms 912 KB Output is correct
35 Correct 233 ms 1256 KB Output is correct
36 Correct 254 ms 1068 KB Output is correct
37 Correct 257 ms 1076 KB Output is correct
38 Correct 266 ms 1312 KB Output is correct
39 Correct 259 ms 1200 KB Output is correct
40 Correct 240 ms 1560 KB Output is correct
41 Correct 265 ms 1200 KB Output is correct
42 Correct 32 ms 948 KB Output is correct
43 Correct 58 ms 1212 KB Output is correct
44 Correct 79 ms 968 KB Output is correct
45 Correct 95 ms 936 KB Output is correct
46 Correct 182 ms 880 KB Output is correct
47 Correct 165 ms 908 KB Output is correct
48 Correct 33 ms 1224 KB Output is correct
49 Correct 33 ms 1316 KB Output is correct