답안 #772683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772683 2023-07-04T10:23:15 Z khshg 기지국 (IOI20_stations) C++14
100 / 100
770 ms 940 KB
#include"stations.h"
#include<bits/stdc++.h>
using namespace std;
 
vector<vector<int>> adj;
int hi;
vector<int> L, R;
vector<bool> flor;
 
void dfs(int s, int p, bool flr) {
	flor[s] = flr;
	bool leaf = 1;
	if(!flr) {
		L[s] = ++hi;
	}
	for(auto& u : adj[s]) {
		if(u == p) continue;
		leaf = 0;
		dfs(u, s, flr ^ 1);
	}
	if(flr) {
		R[s] = ++hi;
	}
}
 
vector<int> label(int N, int K, vector<int> u, vector<int> v) {
	hi = -1;
	flor.resize(N);
	L.resize(N);
	R.resize(N);
	adj.resize(N);
	for(auto& I : adj) I.clear();
	for(int i = 0; i < (int)u.size(); ++i) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0, -1, 0);
	vector<int> labels(N);
	for(int i = 0; i < N; ++i) labels[i] = (flor[i] ? R[i]: L[i]);
	return labels;
}
 
int find_next_station(int s, int t, vector<int> c) {
	if(s == 0) {
		pair<int, int> T = {t, t};
		vector<pair<int, int>> C((int)c.size());
		C[0] = {1, c[0]};
		for(int i = 1; i < (int)c.size(); ++i) {
			C[i] = {c[i - 1] + 1, c[i]};
		}
		for(int i = 0; i < (int)c.size(); ++i) {
			if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
		}
	}
	if(s < c[0]) {
		pair<int, int> S = {s, c.back() - 1}, T = {t, t};
		vector<pair<int, int>> C((int)c.size());
		C[0] = {s + 1, c[0]};
		C.back() = {s, c.back()};
		for(int i = 1; i + 1 < (int)c.size(); ++i) {
			C[i] = {c[i - 1] + 1, c[i]};
		}
		for(int i = 0; i + 1 < (int)c.size(); ++i) {
			if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
		}
		return c.back();
	}
	pair<int, int> S = {c[0] + 1, s}, T = {t, t};
	vector<pair<int, int>> C((int)c.size());
	C.back() = {c.back(), s - 1};
	C[0] = {c[0], s};
	for(int i = 1; i + 1 < (int)c.size(); ++i) {
		C[i] = {c[i], c[i + 1] - 1};
	}
	for(int i = 1; i < (int)c.size(); ++i) {
		if(C[i].first <= T.second && C[i].second >= T.second) return c[i];
	}
	return c[0];
}

Compilation message

stations.cpp: In function 'void dfs(int, int, bool)':
stations.cpp:12:7: warning: variable 'leaf' set but not used [-Wunused-but-set-variable]
   12 |  bool leaf = 1;
      |       ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:56:18: warning: variable 'S' set but not used [-Wunused-but-set-variable]
   56 |   pair<int, int> S = {s, c.back() - 1}, T = {t, t};
      |                  ^
stations.cpp:68:17: warning: variable 'S' set but not used [-Wunused-but-set-variable]
   68 |  pair<int, int> S = {c[0] + 1, s}, T = {t, t};
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 436 ms 676 KB Output is correct
2 Correct 309 ms 584 KB Output is correct
3 Correct 614 ms 416 KB Output is correct
4 Correct 455 ms 420 KB Output is correct
5 Correct 415 ms 420 KB Output is correct
6 Correct 381 ms 636 KB Output is correct
7 Correct 390 ms 548 KB Output is correct
8 Correct 3 ms 556 KB Output is correct
9 Correct 4 ms 496 KB Output is correct
10 Correct 2 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 398 ms 636 KB Output is correct
2 Correct 399 ms 520 KB Output is correct
3 Correct 620 ms 496 KB Output is correct
4 Correct 445 ms 416 KB Output is correct
5 Correct 533 ms 420 KB Output is correct
6 Correct 389 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 387 ms 636 KB Output is correct
2 Correct 276 ms 660 KB Output is correct
3 Correct 744 ms 420 KB Output is correct
4 Correct 584 ms 568 KB Output is correct
5 Correct 478 ms 416 KB Output is correct
6 Correct 367 ms 648 KB Output is correct
7 Correct 343 ms 548 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 2 ms 500 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 468 ms 504 KB Output is correct
12 Correct 426 ms 716 KB Output is correct
13 Correct 375 ms 624 KB Output is correct
14 Correct 417 ms 504 KB Output is correct
15 Correct 47 ms 492 KB Output is correct
16 Correct 67 ms 592 KB Output is correct
17 Correct 78 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 770 ms 552 KB Output is correct
2 Correct 509 ms 504 KB Output is correct
3 Correct 498 ms 544 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 3 ms 500 KB Output is correct
6 Correct 0 ms 500 KB Output is correct
7 Correct 373 ms 416 KB Output is correct
8 Correct 671 ms 416 KB Output is correct
9 Correct 441 ms 544 KB Output is correct
10 Correct 409 ms 504 KB Output is correct
11 Correct 4 ms 492 KB Output is correct
12 Correct 3 ms 492 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 370 ms 420 KB Output is correct
17 Correct 364 ms 508 KB Output is correct
18 Correct 455 ms 424 KB Output is correct
19 Correct 499 ms 420 KB Output is correct
20 Correct 492 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 684 KB Output is correct
2 Correct 363 ms 632 KB Output is correct
3 Correct 571 ms 416 KB Output is correct
4 Correct 564 ms 416 KB Output is correct
5 Correct 494 ms 504 KB Output is correct
6 Correct 433 ms 548 KB Output is correct
7 Correct 437 ms 508 KB Output is correct
8 Correct 2 ms 492 KB Output is correct
9 Correct 3 ms 500 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 443 ms 628 KB Output is correct
12 Correct 491 ms 508 KB Output is correct
13 Correct 755 ms 504 KB Output is correct
14 Correct 601 ms 508 KB Output is correct
15 Correct 544 ms 516 KB Output is correct
16 Correct 370 ms 512 KB Output is correct
17 Correct 436 ms 576 KB Output is correct
18 Correct 371 ms 708 KB Output is correct
19 Correct 282 ms 756 KB Output is correct
20 Correct 366 ms 544 KB Output is correct
21 Correct 42 ms 444 KB Output is correct
22 Correct 57 ms 620 KB Output is correct
23 Correct 69 ms 544 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 3 ms 496 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
29 Correct 364 ms 512 KB Output is correct
30 Correct 424 ms 508 KB Output is correct
31 Correct 371 ms 424 KB Output is correct
32 Correct 411 ms 504 KB Output is correct
33 Correct 413 ms 504 KB Output is correct
34 Correct 224 ms 672 KB Output is correct
35 Correct 269 ms 732 KB Output is correct
36 Correct 397 ms 712 KB Output is correct
37 Correct 425 ms 716 KB Output is correct
38 Correct 426 ms 752 KB Output is correct
39 Correct 368 ms 716 KB Output is correct
40 Correct 351 ms 644 KB Output is correct
41 Correct 426 ms 632 KB Output is correct
42 Correct 45 ms 620 KB Output is correct
43 Correct 74 ms 600 KB Output is correct
44 Correct 118 ms 504 KB Output is correct
45 Correct 133 ms 800 KB Output is correct
46 Correct 263 ms 548 KB Output is correct
47 Correct 239 ms 548 KB Output is correct
48 Correct 45 ms 668 KB Output is correct
49 Correct 37 ms 940 KB Output is correct