답안 #546439

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
546439 2022-04-07T14:32:35 Z jhwest2 기지국 (IOI20_stations) C++17
100 / 100
811 ms 880 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int M = 1e3 + 10;

int N[M], D[M], X[M];
vector<int> G[M];

int g = 0;
void dfs(int p, int u) {
	D[u] = D[p] + 1;
	X[u] = N[u] = ++g;
	for (int x : G[u]) if (p != x) {
		dfs(u, x);
		X[u] = max(X[u], X[x]);
	}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	g = 0;
	for (int i = 0; i < n; i++) {
		G[i].clear();
		N[i] = 0; X[i] = 0; D[i] = 0;
	}
	for (int i = 0; i < n - 1; i++) {
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	dfs(0, 0);

	for (int i = 0; i < n; i++) {
		if (D[i] % 2 == 0) {
			N[i] = X[i];
		}
	}
	vector<tuple<int, int, int>> V;
	for (int i = 0; i < n; i++) {
		V.emplace_back(N[i], -D[i], i);
	}
	sort(V.begin(), V.end());

	vector<int> labels(n);
	for (int i = 0; i < n; i++) {
		auto [a, b, c] = V[i];
		labels[c] = i;
	}
	return labels;
}

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

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:56:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i = 1; i + 1 < c.size(); i++) {
      |                   ~~~~~~^~~~~~~~~~
stations.cpp:64:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for (int i = 1; i + 1 < c.size(); i++) {
      |                   ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 664 KB Output is correct
2 Correct 363 ms 640 KB Output is correct
3 Correct 811 ms 528 KB Output is correct
4 Correct 568 ms 416 KB Output is correct
5 Correct 601 ms 544 KB Output is correct
6 Correct 395 ms 672 KB Output is correct
7 Correct 386 ms 656 KB Output is correct
8 Correct 2 ms 628 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 532 KB Output is correct
2 Correct 506 ms 540 KB Output is correct
3 Correct 758 ms 524 KB Output is correct
4 Correct 556 ms 524 KB Output is correct
5 Correct 472 ms 524 KB Output is correct
6 Correct 424 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 660 KB Output is correct
2 Correct 368 ms 644 KB Output is correct
3 Correct 737 ms 528 KB Output is correct
4 Correct 543 ms 544 KB Output is correct
5 Correct 439 ms 664 KB Output is correct
6 Correct 390 ms 644 KB Output is correct
7 Correct 429 ms 636 KB Output is correct
8 Correct 3 ms 620 KB Output is correct
9 Correct 4 ms 620 KB Output is correct
10 Correct 0 ms 496 KB Output is correct
11 Correct 498 ms 528 KB Output is correct
12 Correct 399 ms 804 KB Output is correct
13 Correct 419 ms 772 KB Output is correct
14 Correct 409 ms 548 KB Output is correct
15 Correct 52 ms 592 KB Output is correct
16 Correct 50 ms 668 KB Output is correct
17 Correct 96 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 716 ms 572 KB Output is correct
2 Correct 549 ms 420 KB Output is correct
3 Correct 513 ms 544 KB Output is correct
4 Correct 4 ms 620 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 513 ms 528 KB Output is correct
8 Correct 773 ms 524 KB Output is correct
9 Correct 577 ms 548 KB Output is correct
10 Correct 518 ms 420 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 5 ms 620 KB Output is correct
13 Correct 5 ms 620 KB Output is correct
14 Correct 4 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 435 ms 532 KB Output is correct
17 Correct 377 ms 548 KB Output is correct
18 Correct 440 ms 528 KB Output is correct
19 Correct 426 ms 420 KB Output is correct
20 Correct 385 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 492 ms 672 KB Output is correct
2 Correct 394 ms 676 KB Output is correct
3 Correct 723 ms 504 KB Output is correct
4 Correct 522 ms 532 KB Output is correct
5 Correct 500 ms 520 KB Output is correct
6 Correct 365 ms 648 KB Output is correct
7 Correct 377 ms 528 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 4 ms 628 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 368 ms 620 KB Output is correct
12 Correct 444 ms 544 KB Output is correct
13 Correct 715 ms 544 KB Output is correct
14 Correct 520 ms 416 KB Output is correct
15 Correct 525 ms 544 KB Output is correct
16 Correct 338 ms 540 KB Output is correct
17 Correct 516 ms 416 KB Output is correct
18 Correct 374 ms 660 KB Output is correct
19 Correct 401 ms 664 KB Output is correct
20 Correct 403 ms 528 KB Output is correct
21 Correct 50 ms 600 KB Output is correct
22 Correct 66 ms 572 KB Output is correct
23 Correct 96 ms 660 KB Output is correct
24 Correct 5 ms 620 KB Output is correct
25 Correct 5 ms 456 KB Output is correct
26 Correct 5 ms 628 KB Output is correct
27 Correct 3 ms 500 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 417 ms 520 KB Output is correct
30 Correct 457 ms 516 KB Output is correct
31 Correct 422 ms 528 KB Output is correct
32 Correct 428 ms 524 KB Output is correct
33 Correct 475 ms 544 KB Output is correct
34 Correct 278 ms 672 KB Output is correct
35 Correct 370 ms 728 KB Output is correct
36 Correct 365 ms 676 KB Output is correct
37 Correct 433 ms 880 KB Output is correct
38 Correct 417 ms 656 KB Output is correct
39 Correct 360 ms 772 KB Output is correct
40 Correct 398 ms 764 KB Output is correct
41 Correct 380 ms 756 KB Output is correct
42 Correct 56 ms 656 KB Output is correct
43 Correct 87 ms 600 KB Output is correct
44 Correct 123 ms 548 KB Output is correct
45 Correct 123 ms 524 KB Output is correct
46 Correct 240 ms 544 KB Output is correct
47 Correct 264 ms 544 KB Output is correct
48 Correct 60 ms 772 KB Output is correct
49 Correct 51 ms 828 KB Output is correct