답안 #306968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306968 2020-09-26T15:30:54 Z FelixMP 기지국 (IOI20_stations) C++14
100 / 100
1033 ms 1136 KB
#include "stations.h"
#include <vector>
#include <algorithm>
#include <utility>
#include <iostream>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

vvi al;
vi rans;
int ft = 0;

ii dfs(int v, int p, int r) {

	int cmin =  1002;
	int cmax = -1;

	for(int i=0; i < (int)al[v].size(); ++i) {
		int u = al[v][i];
		if(u == p) continue;
		ii x = dfs(u, v, !r);

		//cerr << "VISITED " << u << " returned " << x.first << " " << x.second << endl;

		cmin = min(cmin, x.first);
		cmax = max(cmax, x.second);
	}

	if(cmin == 1002) {
		rans[ft] = v;
		ft++;
		return ii(ft-1, ft-1);
	}
	else {
		if(r) {
			for(int i=ft; i > cmax+1; --i) {
				swap(rans[i], rans[i-1]);
			}
			rans[cmax+1] = v;
			ft++;
		}
		else {
			for(int i=ft; i > cmin; --i) {
				swap(rans[i], rans[i-1]);
			}
			rans[cmin] = v;
			ft++;
		}
		return ii(cmin, max(cmax, ft-1));
	}


}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	
	al = vvi(n, vi());
	for(int i=0; i < n-1; ++i) {
		al[u[i]].push_back(v[i]);
		al[v[i]].push_back(u[i]);
	}

	rans = vi(1001, -1);
	ft = 0;

	dfs(0, -1, 0);
	vi ans(n);
	/*for(int i=0; i < 1001; ++i) {
		if(rans[i] != -1) {
			cerr << "rans[" << i << "] = " << rans[i] << endl;
		}
	}*/
	for(int i=0; i < n; ++i) {
		ans[rans[i]] = i;
	}
	return ans;

}

int find_next_station(int s, int t, std::vector<int> c) {
	int m = c.size();
	if(m == 1) return c[0];
	bool ismax = true;
	for(int i=0; i < m; ++i) {
		if(s < c[i]) ismax = false;
	}
	if(s == 0) {
		vi otc;
		for(int i=0; i < m; ++i) {
			 otc.push_back(c[i]);
		}
		sort(otc.begin(), otc.end());
		for(int i=0; i < m; ++i) {
			if(t <= otc[i]) return otc[i];
		}
	}
	else if(ismax) {
		int minv = 1002;
		for(int i=0; i < m; ++i) minv = min(c[i], minv);
		if(t <= minv || t >= s) return minv;
		vi otc;
		for(int i=0; i < m; ++i) {
			if(c[i] != minv) otc.push_back(c[i]);
		}
		sort(otc.begin(), otc.end());
		for(int i=m-2; i > -1; --i) {
			if(t >= otc[i]) return otc[i];
		}
		return minv;
	}
	else {
		int maxv = -1;
		for(int i=0; i < m; ++i) maxv = max(c[i], maxv);
		if(t >= maxv || t <= s) return maxv;
		vi otc;
		for(int i=0; i < m; ++i) {
			if(c[i] != maxv) otc.push_back(c[i]);
		}
		sort(otc.begin(), otc.end());
		for(int i=0; i < m-1; ++i) {
			if(t <= otc[i]) return otc[i];
		}
		return maxv;
	}


}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:130:1: warning: control reaches end of non-void function [-Wreturn-type]
  130 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 1024 KB Output is correct
2 Correct 581 ms 1024 KB Output is correct
3 Correct 931 ms 760 KB Output is correct
4 Correct 667 ms 768 KB Output is correct
5 Correct 651 ms 1024 KB Output is correct
6 Correct 548 ms 1024 KB Output is correct
7 Correct 444 ms 768 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 4 ms 896 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 453 ms 1008 KB Output is correct
2 Correct 519 ms 820 KB Output is correct
3 Correct 1033 ms 784 KB Output is correct
4 Correct 630 ms 892 KB Output is correct
5 Correct 714 ms 796 KB Output is correct
6 Correct 523 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 550 ms 1024 KB Output is correct
2 Correct 456 ms 1008 KB Output is correct
3 Correct 867 ms 768 KB Output is correct
4 Correct 706 ms 768 KB Output is correct
5 Correct 661 ms 768 KB Output is correct
6 Correct 449 ms 1024 KB Output is correct
7 Correct 457 ms 1024 KB Output is correct
8 Correct 3 ms 896 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 639 ms 644 KB Output is correct
12 Correct 490 ms 1024 KB Output is correct
13 Correct 533 ms 1008 KB Output is correct
14 Correct 519 ms 768 KB Output is correct
15 Correct 53 ms 768 KB Output is correct
16 Correct 74 ms 836 KB Output is correct
17 Correct 117 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 905 ms 784 KB Output is correct
2 Correct 721 ms 900 KB Output is correct
3 Correct 609 ms 896 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Correct 4 ms 768 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 728 ms 800 KB Output is correct
8 Correct 958 ms 884 KB Output is correct
9 Correct 753 ms 768 KB Output is correct
10 Correct 622 ms 892 KB Output is correct
11 Correct 7 ms 888 KB Output is correct
12 Correct 7 ms 896 KB Output is correct
13 Correct 4 ms 896 KB Output is correct
14 Correct 5 ms 900 KB Output is correct
15 Correct 1 ms 648 KB Output is correct
16 Correct 535 ms 768 KB Output is correct
17 Correct 513 ms 888 KB Output is correct
18 Correct 495 ms 768 KB Output is correct
19 Correct 513 ms 792 KB Output is correct
20 Correct 492 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 1136 KB Output is correct
2 Correct 510 ms 1008 KB Output is correct
3 Correct 926 ms 760 KB Output is correct
4 Correct 869 ms 884 KB Output is correct
5 Correct 602 ms 640 KB Output is correct
6 Correct 498 ms 1076 KB Output is correct
7 Correct 576 ms 792 KB Output is correct
8 Correct 3 ms 640 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 496 ms 1008 KB Output is correct
12 Correct 652 ms 824 KB Output is correct
13 Correct 957 ms 792 KB Output is correct
14 Correct 728 ms 800 KB Output is correct
15 Correct 660 ms 640 KB Output is correct
16 Correct 516 ms 768 KB Output is correct
17 Correct 736 ms 768 KB Output is correct
18 Correct 493 ms 1008 KB Output is correct
19 Correct 565 ms 1024 KB Output is correct
20 Correct 490 ms 784 KB Output is correct
21 Correct 71 ms 768 KB Output is correct
22 Correct 80 ms 768 KB Output is correct
23 Correct 110 ms 768 KB Output is correct
24 Correct 7 ms 888 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 6 ms 900 KB Output is correct
27 Correct 4 ms 768 KB Output is correct
28 Correct 2 ms 640 KB Output is correct
29 Correct 662 ms 888 KB Output is correct
30 Correct 618 ms 768 KB Output is correct
31 Correct 504 ms 892 KB Output is correct
32 Correct 488 ms 768 KB Output is correct
33 Correct 515 ms 888 KB Output is correct
34 Correct 449 ms 1000 KB Output is correct
35 Correct 476 ms 1024 KB Output is correct
36 Correct 454 ms 1008 KB Output is correct
37 Correct 458 ms 1024 KB Output is correct
38 Correct 504 ms 1024 KB Output is correct
39 Correct 466 ms 1024 KB Output is correct
40 Correct 464 ms 832 KB Output is correct
41 Correct 543 ms 1024 KB Output is correct
42 Correct 62 ms 808 KB Output is correct
43 Correct 101 ms 780 KB Output is correct
44 Correct 124 ms 872 KB Output is correct
45 Correct 200 ms 1024 KB Output is correct
46 Correct 296 ms 788 KB Output is correct
47 Correct 329 ms 1064 KB Output is correct
48 Correct 66 ms 768 KB Output is correct
49 Correct 72 ms 780 KB Output is correct