답안 #580974

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580974 2022-06-22T07:18:44 Z Jomnoi 기지국 (IOI20_stations) C++17
100 / 100
997 ms 864 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;

const int MAX_N = 1005;

int N, timer;
vector <int> graph[MAX_N];
int depth[MAX_N], st[MAX_N], en[MAX_N];

void init(int n) {
	N = n, timer = 0;
	for(int i = 0; i < N; i++) {
		st[i] = en[i] = 0;
		graph[i].clear();
	}
}

void dfs(int u, int p) {
	st[u] = timer++;
	for(auto v : graph[u]) {
		if(v != p) {
			depth[v] = depth[u] + 1;
			dfs(v, u);
		}
	}
	en[u] = timer++;
}

vector <int> label(int n, int k, vector <int> u, vector <int> v) {
	init(n);

	for(int i = 0; i < N - 1; i++) {
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}

	dfs(0, -1);

	vector <int> vec;
	for(int i = 0; i < N; i++) {
		if(depth[i] % 2 == 0) {
			vec.push_back(st[i]);
		}
		else {
			vec.push_back(en[i]);
		}
	}

	sort(vec.begin(), vec.end());

	vector <int> labels(N);
	for(int i = 0; i < N; i++) {
		if(depth[i] % 2 == 0) {
			labels[i] = lower_bound(vec.begin(), vec.end(), st[i]) - vec.begin();
		}
		else {
			labels[i] = lower_bound(vec.begin(), vec.end(), en[i]) - vec.begin();
		}
	}
	return labels;
}

int find_next_station(int s, int t, vector <int> c) {
	if(c[0] > s) { // s is labeled with st
		if(t < s) {
			return c.back();
		}
		for(int i = 0; i < c.size(); i++) {
			if(t <= c[i]) {
				return c[i];	
			}
		}
		return c.back();
	}
	else { // s is labeled with en
		if(t > s) {
			return c[0];
		}
		for(int i = c.size() - 1; i >= 0; i--) {
			if(t >= c[i]) {
				return c[i];
			}
		}
		return c[0];
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int i = 0; i < c.size(); i++) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 544 KB Output is correct
2 Correct 442 ms 528 KB Output is correct
3 Correct 971 ms 532 KB Output is correct
4 Correct 606 ms 548 KB Output is correct
5 Correct 611 ms 544 KB Output is correct
6 Correct 463 ms 536 KB Output is correct
7 Correct 445 ms 600 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 5 ms 500 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 496 ms 532 KB Output is correct
2 Correct 574 ms 544 KB Output is correct
3 Correct 871 ms 528 KB Output is correct
4 Correct 800 ms 536 KB Output is correct
5 Correct 599 ms 544 KB Output is correct
6 Correct 526 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 544 KB Output is correct
2 Correct 423 ms 788 KB Output is correct
3 Correct 997 ms 524 KB Output is correct
4 Correct 602 ms 420 KB Output is correct
5 Correct 591 ms 420 KB Output is correct
6 Correct 416 ms 544 KB Output is correct
7 Correct 467 ms 528 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 5 ms 684 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 527 ms 544 KB Output is correct
12 Correct 470 ms 768 KB Output is correct
13 Correct 519 ms 788 KB Output is correct
14 Correct 408 ms 548 KB Output is correct
15 Correct 54 ms 640 KB Output is correct
16 Correct 57 ms 528 KB Output is correct
17 Correct 87 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 861 ms 524 KB Output is correct
2 Correct 662 ms 532 KB Output is correct
3 Correct 602 ms 544 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 4 ms 492 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 551 ms 532 KB Output is correct
8 Correct 836 ms 652 KB Output is correct
9 Correct 675 ms 528 KB Output is correct
10 Correct 564 ms 532 KB Output is correct
11 Correct 4 ms 668 KB Output is correct
12 Correct 5 ms 492 KB Output is correct
13 Correct 4 ms 500 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 502 ms 588 KB Output is correct
17 Correct 600 ms 520 KB Output is correct
18 Correct 499 ms 536 KB Output is correct
19 Correct 555 ms 484 KB Output is correct
20 Correct 491 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 502 ms 644 KB Output is correct
2 Correct 433 ms 536 KB Output is correct
3 Correct 800 ms 416 KB Output is correct
4 Correct 682 ms 568 KB Output is correct
5 Correct 595 ms 548 KB Output is correct
6 Correct 466 ms 664 KB Output is correct
7 Correct 409 ms 532 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 463 ms 532 KB Output is correct
12 Correct 486 ms 740 KB Output is correct
13 Correct 940 ms 528 KB Output is correct
14 Correct 742 ms 528 KB Output is correct
15 Correct 650 ms 528 KB Output is correct
16 Correct 504 ms 528 KB Output is correct
17 Correct 689 ms 420 KB Output is correct
18 Correct 421 ms 652 KB Output is correct
19 Correct 391 ms 808 KB Output is correct
20 Correct 470 ms 532 KB Output is correct
21 Correct 51 ms 600 KB Output is correct
22 Correct 77 ms 672 KB Output is correct
23 Correct 111 ms 536 KB Output is correct
24 Correct 5 ms 748 KB Output is correct
25 Correct 6 ms 492 KB Output is correct
26 Correct 5 ms 500 KB Output is correct
27 Correct 4 ms 628 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 542 ms 532 KB Output is correct
30 Correct 475 ms 532 KB Output is correct
31 Correct 390 ms 532 KB Output is correct
32 Correct 492 ms 540 KB Output is correct
33 Correct 564 ms 544 KB Output is correct
34 Correct 385 ms 560 KB Output is correct
35 Correct 413 ms 672 KB Output is correct
36 Correct 447 ms 648 KB Output is correct
37 Correct 521 ms 656 KB Output is correct
38 Correct 420 ms 760 KB Output is correct
39 Correct 444 ms 632 KB Output is correct
40 Correct 491 ms 776 KB Output is correct
41 Correct 457 ms 760 KB Output is correct
42 Correct 58 ms 544 KB Output is correct
43 Correct 111 ms 672 KB Output is correct
44 Correct 131 ms 628 KB Output is correct
45 Correct 156 ms 544 KB Output is correct
46 Correct 350 ms 604 KB Output is correct
47 Correct 347 ms 548 KB Output is correct
48 Correct 62 ms 784 KB Output is correct
49 Correct 62 ms 864 KB Output is correct