답안 #429307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429307 2021-06-15T20:27:15 Z AugustinasJucas 기지국 (IOI20_stations) C++14
100 / 100
1257 ms 896 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int dydis = 1000;
vector<int> gr[dydis];
int enter[dydis];
int leave[dydis];
vector<int> ret (dydis);
int dbInd = 0;
void dfs(int v, int came, int h = 0){
	enter[v] = dbInd++;
	for(auto x : gr[v]){
		if(x == came) continue;
		dfs(x, v, h+1);
	}
	leave[v] = dbInd++;
	//cout << "enter[" << v << "] = " << enter[v] << ", leave[" << v << "] = " << leave[v] << ", ";
	if(h & 1){
		//cout << "dedu leave" << endl;
		ret[v] = leave[v];
	}else{
		ret[v] = enter[v];
		//cout << "dedu enter" << endl;
	}
}
vector<int> compress(vector<int> a){
	vector<int> ret;
	auto cp = a;
	sort(cp.begin(), cp.end());
	for(auto x : a){
		ret.push_back(lower_bound(cp.begin(), cp.end(), x) - cp.begin());
	}
	//cout << "{"; for(auto x : a) cout << x  << " "; cout << "} -> {"; for(auto x : ret) cout << x << " "; cout << "}\n\n";
	return ret;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	for(int i = 0; i < n; i++){
		gr[i].clear();
	}
	dbInd = 0;
	ret.resize(n);
	for(int i = 0; i < n-1; i++){
		gr[u[i]].push_back(v[i]);
		gr[v[i]].push_back(u[i]);
	}
	dfs(0, -1);
	ret = compress(ret);
	return ret;
}

int find_next_station(int s, int t, vector<int> c) {
	
	bool yraMaz = 1;
	for(auto x : c){
		if(x < s) yraMaz = 0;
	}
	if(yraMaz){
		int dd = c.back();
		int last = s+1;
		//cout << s << " yra enter" << endl;
		for(auto x : c){
			if(x == dd && s != 0) continue;
			int enter = last;
			int leave = x;
			//cout << "gaunu [" << enter << "; " << leave << "]\n";
			if(enter <= t && t <= leave) return x;
			last = leave;
		}
		return c.back();
	}else{ 
		//cout << s << " yra leave" << endl;

		for(int i = 1; i < (int)c.size(); i++){
			int enter = c[i];
			int leave = (i == (int)c.size() - 1 ? s  : c[i+1] ) - 1;
			//cout << c[i] << ", enter: " << enter << ", leave: " << leave << endl;
			if(enter <= t && t <= leave){
				return c[i];
			}
		}
		return c[0];
	}
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 730 ms 656 KB Output is correct
2 Correct 544 ms 640 KB Output is correct
3 Correct 1029 ms 400 KB Output is correct
4 Correct 734 ms 400 KB Output is correct
5 Correct 657 ms 516 KB Output is correct
6 Correct 602 ms 648 KB Output is correct
7 Correct 460 ms 528 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 565 ms 520 KB Output is correct
2 Correct 738 ms 640 KB Output is correct
3 Correct 1257 ms 656 KB Output is correct
4 Correct 739 ms 656 KB Output is correct
5 Correct 688 ms 532 KB Output is correct
6 Correct 650 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 764 ms 856 KB Output is correct
2 Correct 525 ms 640 KB Output is correct
3 Correct 962 ms 400 KB Output is correct
4 Correct 874 ms 400 KB Output is correct
5 Correct 874 ms 400 KB Output is correct
6 Correct 616 ms 780 KB Output is correct
7 Correct 699 ms 528 KB Output is correct
8 Correct 4 ms 676 KB Output is correct
9 Correct 3 ms 528 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 827 ms 400 KB Output is correct
12 Correct 593 ms 752 KB Output is correct
13 Correct 558 ms 756 KB Output is correct
14 Correct 490 ms 528 KB Output is correct
15 Correct 58 ms 604 KB Output is correct
16 Correct 87 ms 712 KB Output is correct
17 Correct 98 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1020 ms 676 KB Output is correct
2 Correct 964 ms 400 KB Output is correct
3 Correct 760 ms 528 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 6 ms 596 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 743 ms 528 KB Output is correct
8 Correct 1029 ms 584 KB Output is correct
9 Correct 784 ms 524 KB Output is correct
10 Correct 876 ms 516 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 7 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 652 ms 656 KB Output is correct
17 Correct 645 ms 528 KB Output is correct
18 Correct 699 ms 544 KB Output is correct
19 Correct 618 ms 528 KB Output is correct
20 Correct 640 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 612 ms 648 KB Output is correct
2 Correct 600 ms 656 KB Output is correct
3 Correct 1164 ms 524 KB Output is correct
4 Correct 733 ms 644 KB Output is correct
5 Correct 753 ms 520 KB Output is correct
6 Correct 612 ms 672 KB Output is correct
7 Correct 475 ms 520 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 7 ms 724 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 524 ms 520 KB Output is correct
12 Correct 689 ms 528 KB Output is correct
13 Correct 1089 ms 528 KB Output is correct
14 Correct 786 ms 600 KB Output is correct
15 Correct 922 ms 528 KB Output is correct
16 Correct 728 ms 520 KB Output is correct
17 Correct 746 ms 400 KB Output is correct
18 Correct 629 ms 760 KB Output is correct
19 Correct 695 ms 844 KB Output is correct
20 Correct 525 ms 716 KB Output is correct
21 Correct 65 ms 764 KB Output is correct
22 Correct 89 ms 676 KB Output is correct
23 Correct 138 ms 860 KB Output is correct
24 Correct 9 ms 592 KB Output is correct
25 Correct 9 ms 596 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 5 ms 800 KB Output is correct
28 Correct 2 ms 448 KB Output is correct
29 Correct 747 ms 520 KB Output is correct
30 Correct 703 ms 528 KB Output is correct
31 Correct 774 ms 400 KB Output is correct
32 Correct 746 ms 528 KB Output is correct
33 Correct 728 ms 576 KB Output is correct
34 Correct 446 ms 840 KB Output is correct
35 Correct 563 ms 644 KB Output is correct
36 Correct 504 ms 660 KB Output is correct
37 Correct 533 ms 816 KB Output is correct
38 Correct 675 ms 716 KB Output is correct
39 Correct 514 ms 684 KB Output is correct
40 Correct 592 ms 636 KB Output is correct
41 Correct 624 ms 636 KB Output is correct
42 Correct 89 ms 712 KB Output is correct
43 Correct 141 ms 648 KB Output is correct
44 Correct 166 ms 608 KB Output is correct
45 Correct 168 ms 520 KB Output is correct
46 Correct 477 ms 780 KB Output is correct
47 Correct 444 ms 708 KB Output is correct
48 Correct 78 ms 780 KB Output is correct
49 Correct 81 ms 896 KB Output is correct