답안 #430194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430194 2021-06-16T12:00:45 Z amoo_safar 기지국 (IOI20_stations) C++17
100 / 100
1380 ms 916 KB
#include "stations.h"

#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;

const int N = 2020;

vector<int> G[N];
int T = 0;
int st[N];

void DFS(int u, int p, int d){
	if(d)
		st[u] = T ++;

	for(auto adj : G[u])
		if(adj != p)
			DFS(adj, u, d ^ 1);

	if(!d)
		st[u] = T ++;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	T = 0;
	for(int i = 0; i < n; i++) G[i].clear();

	for(int i = 0; i < n - 1; i++)
		G[u[i]].pb(v[i]), G[v[i]].pb(u[i]);
	DFS(0, -1, 1);
	vector<int> labels(n);
	for (int i = 0; i < n; i++)
		labels[i] = st[i];
	// cerr << "edges {\n";
	// for(int i = 0; i < n - 1; i++)
	// 	cerr << u[i] << " -> " << v[i] << '\n';
	// cerr << "}\n";
	// for(int i = 0; i < n; i++)
	// 	cerr << i << " : " << labels[i] << '\n';
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int sz = c.size();
	if(s == 0){
		sort(all(c));
		for(auto x : c)
			if(t <= x)
				return x;
		return c[0];
	}
	if(s < c[0]){
		sort(all(c));
		int dad = c.back();
		if(t < s) return dad;
		for(int i = 0; i < sz - 1; i++){
			if(t <= c[i])
				return c[i];
		}
		return dad;
	} else {
		sort(all(c));
		int dad = c[0];
		if(t > s) return dad;
		for(int i = sz - 1; i > 0; i--){
			if(t >= c[i])
				return c[i];
		}
		return dad;
	}
	return c[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 741 ms 772 KB Output is correct
2 Correct 523 ms 788 KB Output is correct
3 Correct 1285 ms 656 KB Output is correct
4 Correct 803 ms 656 KB Output is correct
5 Correct 614 ms 656 KB Output is correct
6 Correct 713 ms 784 KB Output is correct
7 Correct 593 ms 784 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 2 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 671 ms 656 KB Output is correct
2 Correct 668 ms 676 KB Output is correct
3 Correct 968 ms 656 KB Output is correct
4 Correct 678 ms 656 KB Output is correct
5 Correct 705 ms 656 KB Output is correct
6 Correct 546 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 597 ms 784 KB Output is correct
2 Correct 613 ms 784 KB Output is correct
3 Correct 1380 ms 656 KB Output is correct
4 Correct 976 ms 656 KB Output is correct
5 Correct 735 ms 660 KB Output is correct
6 Correct 475 ms 784 KB Output is correct
7 Correct 646 ms 656 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 4 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 711 ms 672 KB Output is correct
12 Correct 759 ms 792 KB Output is correct
13 Correct 598 ms 896 KB Output is correct
14 Correct 502 ms 660 KB Output is correct
15 Correct 81 ms 656 KB Output is correct
16 Correct 120 ms 656 KB Output is correct
17 Correct 118 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1043 ms 656 KB Output is correct
2 Correct 1119 ms 656 KB Output is correct
3 Correct 921 ms 748 KB Output is correct
4 Correct 4 ms 672 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 597 ms 656 KB Output is correct
8 Correct 1103 ms 656 KB Output is correct
9 Correct 819 ms 672 KB Output is correct
10 Correct 664 ms 656 KB Output is correct
11 Correct 9 ms 720 KB Output is correct
12 Correct 9 ms 772 KB Output is correct
13 Correct 3 ms 676 KB Output is correct
14 Correct 4 ms 724 KB Output is correct
15 Correct 2 ms 704 KB Output is correct
16 Correct 562 ms 756 KB Output is correct
17 Correct 635 ms 708 KB Output is correct
18 Correct 629 ms 668 KB Output is correct
19 Correct 669 ms 656 KB Output is correct
20 Correct 753 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 754 ms 664 KB Output is correct
2 Correct 769 ms 792 KB Output is correct
3 Correct 1365 ms 656 KB Output is correct
4 Correct 731 ms 664 KB Output is correct
5 Correct 760 ms 656 KB Output is correct
6 Correct 651 ms 780 KB Output is correct
7 Correct 650 ms 656 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 532 ms 656 KB Output is correct
12 Correct 703 ms 680 KB Output is correct
13 Correct 1055 ms 656 KB Output is correct
14 Correct 980 ms 656 KB Output is correct
15 Correct 688 ms 656 KB Output is correct
16 Correct 590 ms 656 KB Output is correct
17 Correct 770 ms 784 KB Output is correct
18 Correct 594 ms 676 KB Output is correct
19 Correct 645 ms 792 KB Output is correct
20 Correct 490 ms 656 KB Output is correct
21 Correct 74 ms 704 KB Output is correct
22 Correct 102 ms 660 KB Output is correct
23 Correct 176 ms 656 KB Output is correct
24 Correct 4 ms 724 KB Output is correct
25 Correct 9 ms 724 KB Output is correct
26 Correct 5 ms 656 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 2 ms 720 KB Output is correct
29 Correct 668 ms 724 KB Output is correct
30 Correct 708 ms 664 KB Output is correct
31 Correct 586 ms 668 KB Output is correct
32 Correct 631 ms 676 KB Output is correct
33 Correct 618 ms 656 KB Output is correct
34 Correct 428 ms 656 KB Output is correct
35 Correct 604 ms 916 KB Output is correct
36 Correct 486 ms 784 KB Output is correct
37 Correct 534 ms 664 KB Output is correct
38 Correct 645 ms 664 KB Output is correct
39 Correct 663 ms 712 KB Output is correct
40 Correct 621 ms 664 KB Output is correct
41 Correct 526 ms 784 KB Output is correct
42 Correct 93 ms 656 KB Output is correct
43 Correct 121 ms 816 KB Output is correct
44 Correct 145 ms 656 KB Output is correct
45 Correct 192 ms 656 KB Output is correct
46 Correct 409 ms 656 KB Output is correct
47 Correct 317 ms 656 KB Output is correct
48 Correct 78 ms 688 KB Output is correct
49 Correct 81 ms 832 KB Output is correct