답안 #1073932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073932 2024-08-25T04:21:51 Z LCJLY 기지국 (IOI20_stations) C++14
100 / 100
663 ms 1184 KB
#include "stations.h"
//#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;

#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii; 

vector<int>adj[1005];
bool visited[1005];
int d[1005];
vector<int>ans;
int ptr=0;

void dfs(int index, int par){
	if(d[index]%2==0) ans[index]=ptr++;	
	for(auto it:adj[index]){
		if(it==par) continue;
		d[it]=d[index]+1;
		dfs(it,index);
	}	
	if(d[index]%2==1) ans[index]=ptr++;
}

vector<int>label(int n, int k, vector<int>u, vector<int>v) {
	for(int x=0;x<=n;x++){
		adj[x].clear();
		visited[x]=0;
		d[x]=0;
	}
	ans.clear();
	ans=vector<int>(n,0);
	ptr=0;
	for(int x=0;x<n-1;x++){
		adj[u[x]].push_back(v[x]);
		adj[v[x]].push_back(u[x]);
	}
	
	dfs(0,-1);
	//show4(ans,ans);
	return ans;
}

int find_next_station(int s, int t, vector<int> c) {
	int maxi=0;
	for(auto it:c) maxi=max(maxi,it);
	if(s>maxi){
		vector<int>v;
		for(auto it:c) v.push_back(it);
		//s is out
		sort(v.begin(),v.end());
		int sz=v.size();
		v.push_back(s);
		for(int x=1;x<sz;x++){
			int l=v[x];
			int r=v[x+1]-1;
			if(l<=t&&r>=t){
				return v[x];
			}
		}
		return v[0];
	} 
	else{
		//s is in
		vector<int>v;
		for(auto it:c) v.push_back(it);
		v.push_back(s-1);
		sort(v.begin(),v.end());
		int sz=v.size();
		for(int x=1;x<sz-1;x++){
			int l=v[x-1]+1;
			int r=v[x];
			if(l<=t&&r>=t){
				return v[x];
			}
		}
		return c.back();
	}
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 397 ms 684 KB Output is correct
2 Correct 317 ms 684 KB Output is correct
3 Correct 564 ms 684 KB Output is correct
4 Correct 464 ms 684 KB Output is correct
5 Correct 414 ms 684 KB Output is correct
6 Correct 301 ms 684 KB Output is correct
7 Correct 302 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 1 ms 776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 297 ms 684 KB Output is correct
2 Correct 370 ms 684 KB Output is correct
3 Correct 663 ms 688 KB Output is correct
4 Correct 470 ms 684 KB Output is correct
5 Correct 421 ms 684 KB Output is correct
6 Correct 293 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 684 KB Output is correct
2 Correct 316 ms 688 KB Output is correct
3 Correct 630 ms 688 KB Output is correct
4 Correct 432 ms 684 KB Output is correct
5 Correct 436 ms 684 KB Output is correct
6 Correct 310 ms 684 KB Output is correct
7 Correct 334 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 772 KB Output is correct
10 Correct 0 ms 776 KB Output is correct
11 Correct 394 ms 944 KB Output is correct
12 Correct 319 ms 940 KB Output is correct
13 Correct 353 ms 788 KB Output is correct
14 Correct 308 ms 684 KB Output is correct
15 Correct 39 ms 768 KB Output is correct
16 Correct 39 ms 760 KB Output is correct
17 Correct 74 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 641 ms 684 KB Output is correct
2 Correct 502 ms 684 KB Output is correct
3 Correct 440 ms 688 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 3 ms 764 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 442 ms 800 KB Output is correct
8 Correct 647 ms 688 KB Output is correct
9 Correct 455 ms 684 KB Output is correct
10 Correct 430 ms 688 KB Output is correct
11 Correct 2 ms 768 KB Output is correct
12 Correct 4 ms 768 KB Output is correct
13 Correct 2 ms 780 KB Output is correct
14 Correct 2 ms 764 KB Output is correct
15 Correct 1 ms 772 KB Output is correct
16 Correct 360 ms 684 KB Output is correct
17 Correct 343 ms 684 KB Output is correct
18 Correct 368 ms 684 KB Output is correct
19 Correct 356 ms 684 KB Output is correct
20 Correct 340 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 375 ms 684 KB Output is correct
2 Correct 302 ms 684 KB Output is correct
3 Correct 653 ms 684 KB Output is correct
4 Correct 445 ms 684 KB Output is correct
5 Correct 437 ms 684 KB Output is correct
6 Correct 331 ms 684 KB Output is correct
7 Correct 317 ms 684 KB Output is correct
8 Correct 1 ms 776 KB Output is correct
9 Correct 2 ms 776 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 315 ms 684 KB Output is correct
12 Correct 401 ms 684 KB Output is correct
13 Correct 623 ms 684 KB Output is correct
14 Correct 461 ms 684 KB Output is correct
15 Correct 432 ms 684 KB Output is correct
16 Correct 280 ms 684 KB Output is correct
17 Correct 391 ms 684 KB Output is correct
18 Correct 301 ms 812 KB Output is correct
19 Correct 339 ms 1184 KB Output is correct
20 Correct 352 ms 684 KB Output is correct
21 Correct 28 ms 768 KB Output is correct
22 Correct 35 ms 768 KB Output is correct
23 Correct 70 ms 744 KB Output is correct
24 Correct 3 ms 768 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 768 KB Output is correct
27 Correct 2 ms 768 KB Output is correct
28 Correct 0 ms 764 KB Output is correct
29 Correct 355 ms 688 KB Output is correct
30 Correct 353 ms 684 KB Output is correct
31 Correct 378 ms 684 KB Output is correct
32 Correct 331 ms 684 KB Output is correct
33 Correct 379 ms 684 KB Output is correct
34 Correct 213 ms 684 KB Output is correct
35 Correct 329 ms 804 KB Output is correct
36 Correct 318 ms 792 KB Output is correct
37 Correct 351 ms 800 KB Output is correct
38 Correct 346 ms 936 KB Output is correct
39 Correct 339 ms 940 KB Output is correct
40 Correct 309 ms 1044 KB Output is correct
41 Correct 316 ms 1012 KB Output is correct
42 Correct 33 ms 768 KB Output is correct
43 Correct 84 ms 744 KB Output is correct
44 Correct 86 ms 732 KB Output is correct
45 Correct 108 ms 716 KB Output is correct
46 Correct 192 ms 684 KB Output is correct
47 Correct 200 ms 684 KB Output is correct
48 Correct 37 ms 776 KB Output is correct
49 Correct 34 ms 888 KB Output is correct