답안 #718276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718276 2023-04-03T19:27:22 Z duchuy297 기지국 (IOI20_stations) C++17
100 / 100
955 ms 832 KB
#include "stations.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
vector<int> adj[N];
int cnt;
vector<int> res;
int ti[N],to[N],lv[N];
void dfs (int u, int p) {
	ti[u] = cnt++;
	for (auto v : adj[u]) {
		if (v == p) continue;
		lv[v] = (lv[u] ^ 1);
		dfs(v,u);
	}
	to[u] = cnt++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	cnt = 0;
	res.resize(n);
	for (int i=0; i<n; i++) adj[i].clear();
	for (int i=0; i<n-1; i++) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs (0,0);
	vector<pair<int,int> > p;
	for (int i=0; i<n; i++) {
		if (lv[i] % 2) p.push_back({ti[i],i});
		else p.push_back({to[i],i});
	}
	sort (p.begin(),p.end());
	int g = 0;
	for (auto u : p) res[u.second] = g++;
	return res;
}
int find_next_station(int s, int t, vector<int> c) {
	sort (c.begin(),c.end());
	if (s < c[0]) { // in
		if (t < s) return c.back(); // father
		// ti[s] >= t
		for (int i=0; i<(int)c.size()-1; i++) {
			if (c[i] >= t)  return c[i];
		}
		return c.back();
	}
	else { // out
		if (t > s) return c[0]; // father
		// to[s] >= t
		for (int i=(int) c.size() - 1; i>=1; i--) {
			if (c[i] <= t) return c[i];
		}
		return c[0];
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 660 KB Output is correct
2 Correct 432 ms 660 KB Output is correct
3 Correct 904 ms 416 KB Output is correct
4 Correct 706 ms 544 KB Output is correct
5 Correct 561 ms 528 KB Output is correct
6 Correct 456 ms 536 KB Output is correct
7 Correct 494 ms 536 KB Output is correct
8 Correct 2 ms 488 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 0 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 516 KB Output is correct
2 Correct 512 ms 584 KB Output is correct
3 Correct 886 ms 508 KB Output is correct
4 Correct 633 ms 536 KB Output is correct
5 Correct 676 ms 416 KB Output is correct
6 Correct 358 ms 532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 473 ms 672 KB Output is correct
2 Correct 450 ms 672 KB Output is correct
3 Correct 785 ms 516 KB Output is correct
4 Correct 681 ms 524 KB Output is correct
5 Correct 591 ms 548 KB Output is correct
6 Correct 467 ms 660 KB Output is correct
7 Correct 398 ms 532 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 5 ms 616 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 552 ms 532 KB Output is correct
12 Correct 457 ms 768 KB Output is correct
13 Correct 493 ms 760 KB Output is correct
14 Correct 543 ms 544 KB Output is correct
15 Correct 55 ms 600 KB Output is correct
16 Correct 62 ms 688 KB Output is correct
17 Correct 129 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 832 ms 576 KB Output is correct
2 Correct 674 ms 544 KB Output is correct
3 Correct 643 ms 416 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 5 ms 500 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 560 ms 532 KB Output is correct
8 Correct 888 ms 524 KB Output is correct
9 Correct 762 ms 540 KB Output is correct
10 Correct 629 ms 676 KB Output is correct
11 Correct 5 ms 620 KB Output is correct
12 Correct 6 ms 568 KB Output is correct
13 Correct 6 ms 620 KB Output is correct
14 Correct 4 ms 492 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 525 ms 532 KB Output is correct
17 Correct 508 ms 420 KB Output is correct
18 Correct 580 ms 548 KB Output is correct
19 Correct 574 ms 540 KB Output is correct
20 Correct 452 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 620 ms 660 KB Output is correct
2 Correct 512 ms 648 KB Output is correct
3 Correct 955 ms 524 KB Output is correct
4 Correct 735 ms 544 KB Output is correct
5 Correct 575 ms 536 KB Output is correct
6 Correct 465 ms 528 KB Output is correct
7 Correct 487 ms 528 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 4 ms 628 KB Output is correct
10 Correct 2 ms 500 KB Output is correct
11 Correct 485 ms 804 KB Output is correct
12 Correct 625 ms 580 KB Output is correct
13 Correct 929 ms 420 KB Output is correct
14 Correct 597 ms 532 KB Output is correct
15 Correct 575 ms 548 KB Output is correct
16 Correct 378 ms 536 KB Output is correct
17 Correct 611 ms 532 KB Output is correct
18 Correct 501 ms 656 KB Output is correct
19 Correct 531 ms 780 KB Output is correct
20 Correct 434 ms 544 KB Output is correct
21 Correct 41 ms 576 KB Output is correct
22 Correct 73 ms 652 KB Output is correct
23 Correct 102 ms 536 KB Output is correct
24 Correct 4 ms 620 KB Output is correct
25 Correct 6 ms 620 KB Output is correct
26 Correct 5 ms 620 KB Output is correct
27 Correct 4 ms 488 KB Output is correct
28 Correct 3 ms 492 KB Output is correct
29 Correct 556 ms 520 KB Output is correct
30 Correct 456 ms 420 KB Output is correct
31 Correct 512 ms 524 KB Output is correct
32 Correct 571 ms 532 KB Output is correct
33 Correct 447 ms 544 KB Output is correct
34 Correct 387 ms 676 KB Output is correct
35 Correct 431 ms 760 KB Output is correct
36 Correct 516 ms 772 KB Output is correct
37 Correct 498 ms 652 KB Output is correct
38 Correct 429 ms 744 KB Output is correct
39 Correct 435 ms 648 KB Output is correct
40 Correct 475 ms 764 KB Output is correct
41 Correct 498 ms 644 KB Output is correct
42 Correct 70 ms 544 KB Output is correct
43 Correct 95 ms 684 KB Output is correct
44 Correct 133 ms 544 KB Output is correct
45 Correct 140 ms 528 KB Output is correct
46 Correct 306 ms 528 KB Output is correct
47 Correct 270 ms 524 KB Output is correct
48 Correct 53 ms 832 KB Output is correct
49 Correct 52 ms 824 KB Output is correct