답안 #397938

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397938 2021-05-03T12:04:13 Z cfalas 기지국 (IOI20_stations) C++14
100 / 100
1285 ms 864 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

vector<vi> adj;
vi labels;
int cnt=0;
vi sub;
int d=0;
void dfs(int s, int p=-1){
	d++;
	//cout<<"enter "<<s<<" "<<cnt<<endl;
	labels[s] = cnt++;
	for(auto v : adj[s]) if(v!=p) dfs(v, s), sub[s]+=sub[v];
	d--;
	//cout<<"leave "<<s<<" "<<cnt<<endl;
	if(d%2==1) labels[s] = cnt;
	cnt++;

}

vi label(int n, int k, std::vector<int> u, std::vector<int> v) {
	cnt = 0;
	adj.assign(n, vi());
	sub.assign(n, 1);
	labels.assign(n, 0);
	FOR(i,n-1){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0);
	//FOR(i,n) cout<<labels[i]<<" "<<sub[i]-1<<endl;

	//FOA(v, labels) cout<<v<<" "; cout<<endl;
	map<int, int> used;
	int t=0;
	set<int> all;
	map<int, int> m;
	FOA(v,labels) all.insert(v);
	FOA(v,all) m[v]=t++;
	FOR(i,n) labels[i] = m[labels[i]];

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	if(s<c[0]){
		// s is t_in
		// c is t_out
		//cout<<s<<" "<<t<<endl;
		int prev = s;
		FOA(v,c){
			if(prev<t && t<=v) return v;
			prev = v;
		}
		return c.back();
	}
	else{
		// s is t_out
		// c is t_in
		//cout<<s<<" "<<t<<endl;
		reverse(c.begin(), c.end());
		//cout<<"N: "; FOA(v,c) cout<<v<<" ";
		//cout<<endl;
		int prev = s;
		FOA(v,c){
			if(v<=t && t<prev) return v;
			prev = v;
		}
		return c.back();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 632 ms 656 KB Output is correct
2 Correct 597 ms 624 KB Output is correct
3 Correct 934 ms 400 KB Output is correct
4 Correct 736 ms 488 KB Output is correct
5 Correct 653 ms 536 KB Output is correct
6 Correct 532 ms 616 KB Output is correct
7 Correct 606 ms 656 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 6 ms 480 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 604 KB Output is correct
2 Correct 547 ms 656 KB Output is correct
3 Correct 992 ms 400 KB Output is correct
4 Correct 682 ms 400 KB Output is correct
5 Correct 914 ms 400 KB Output is correct
6 Correct 472 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 615 ms 624 KB Output is correct
2 Correct 464 ms 656 KB Output is correct
3 Correct 1053 ms 480 KB Output is correct
4 Correct 778 ms 400 KB Output is correct
5 Correct 803 ms 400 KB Output is correct
6 Correct 431 ms 700 KB Output is correct
7 Correct 500 ms 612 KB Output is correct
8 Correct 3 ms 472 KB Output is correct
9 Correct 5 ms 468 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 732 ms 528 KB Output is correct
12 Correct 605 ms 832 KB Output is correct
13 Correct 526 ms 700 KB Output is correct
14 Correct 553 ms 656 KB Output is correct
15 Correct 71 ms 400 KB Output is correct
16 Correct 67 ms 528 KB Output is correct
17 Correct 124 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1285 ms 400 KB Output is correct
2 Correct 713 ms 496 KB Output is correct
3 Correct 697 ms 496 KB Output is correct
4 Correct 2 ms 472 KB Output is correct
5 Correct 6 ms 472 KB Output is correct
6 Correct 2 ms 472 KB Output is correct
7 Correct 621 ms 480 KB Output is correct
8 Correct 962 ms 400 KB Output is correct
9 Correct 784 ms 528 KB Output is correct
10 Correct 855 ms 496 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 4 ms 472 KB Output is correct
13 Correct 6 ms 488 KB Output is correct
14 Correct 4 ms 480 KB Output is correct
15 Correct 4 ms 472 KB Output is correct
16 Correct 605 ms 488 KB Output is correct
17 Correct 520 ms 528 KB Output is correct
18 Correct 586 ms 400 KB Output is correct
19 Correct 621 ms 400 KB Output is correct
20 Correct 673 ms 400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 547 ms 764 KB Output is correct
2 Correct 449 ms 656 KB Output is correct
3 Correct 988 ms 400 KB Output is correct
4 Correct 732 ms 496 KB Output is correct
5 Correct 704 ms 528 KB Output is correct
6 Correct 612 ms 620 KB Output is correct
7 Correct 491 ms 660 KB Output is correct
8 Correct 2 ms 480 KB Output is correct
9 Correct 5 ms 472 KB Output is correct
10 Correct 2 ms 472 KB Output is correct
11 Correct 494 ms 668 KB Output is correct
12 Correct 591 ms 588 KB Output is correct
13 Correct 1079 ms 400 KB Output is correct
14 Correct 890 ms 492 KB Output is correct
15 Correct 694 ms 400 KB Output is correct
16 Correct 512 ms 620 KB Output is correct
17 Correct 635 ms 400 KB Output is correct
18 Correct 439 ms 736 KB Output is correct
19 Correct 620 ms 684 KB Output is correct
20 Correct 459 ms 620 KB Output is correct
21 Correct 68 ms 420 KB Output is correct
22 Correct 96 ms 528 KB Output is correct
23 Correct 139 ms 656 KB Output is correct
24 Correct 7 ms 472 KB Output is correct
25 Correct 5 ms 472 KB Output is correct
26 Correct 4 ms 480 KB Output is correct
27 Correct 4 ms 472 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 685 ms 400 KB Output is correct
30 Correct 517 ms 492 KB Output is correct
31 Correct 668 ms 492 KB Output is correct
32 Correct 710 ms 488 KB Output is correct
33 Correct 487 ms 400 KB Output is correct
34 Correct 393 ms 824 KB Output is correct
35 Correct 459 ms 864 KB Output is correct
36 Correct 591 ms 732 KB Output is correct
37 Correct 561 ms 840 KB Output is correct
38 Correct 682 ms 624 KB Output is correct
39 Correct 613 ms 800 KB Output is correct
40 Correct 583 ms 776 KB Output is correct
41 Correct 457 ms 708 KB Output is correct
42 Correct 61 ms 584 KB Output is correct
43 Correct 143 ms 656 KB Output is correct
44 Correct 171 ms 660 KB Output is correct
45 Correct 190 ms 656 KB Output is correct
46 Correct 434 ms 528 KB Output is correct
47 Correct 351 ms 656 KB Output is correct
48 Correct 82 ms 804 KB Output is correct
49 Correct 73 ms 836 KB Output is correct