답안 #900142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900142 2024-01-07T18:06:38 Z Malix 기지국 (IOI20_stations) C++14
100 / 100
527 ms 1628 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair

void doLess(int a,vi &labels,vi &s,vector<vi> &paths,vi &parent);
void doMore(int a,vi &labels,vi &s,vector<vi> &paths,vi &parent);

int dp(int a,vi &parent,vector<vi> &paths,vi &s){
	if(paths[a].size()==1)return 1;
	for(auto u:paths[a]){
		if(u==parent[a])continue;
		parent[u]=a;
		s[a]+=dp(u,parent,paths,s);
	}
	return s[a];
}

void doLess(int a,vi &labels,vi &s,vector<vi> &paths,vi &parent){
	int d=labels[a];
	for(auto u:paths[a]){
		if(u==parent[a])continue;
		labels[u]=d-s[u];
		doMore(u,labels,s,paths,parent);
		d=labels[u];
	}
}

void doMore(int a,vi &labels,vi &s,vector<vi> &paths,vi &parent){
	int d=labels[a];
	for(auto u:paths[a]){
		if(u==parent[a])continue;
		labels[u]=d+s[u];
		doLess(u,labels,s,paths,parent);
		d=labels[u];
	}
	
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	
	std::vector<int> labels(n);
	vector<vi> paths(n);
	REP(i,0,n-1){
		paths[u[i]].PB(v[i]);
		paths[v[i]].PB(u[i]);
	}
	vi parent(n);
	parent[0]=0;
	vi s(n,1);
	for(auto u:paths[0]){
		parent[u]=0;
		s[0]+=dp(u,parent,paths,s);
	}
	labels[0]=0;
	int d=0;
	for(auto u:paths[0]){
		labels[u]=d+s[u];
		doLess(u,labels,s,paths,parent);
		d=labels[u];
	}
	//REP(i,0,n)cout<<labels[i]<<" ";
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size()==1)return c[0];
	if(s==0){
		auto it=lower_bound(c.begin(),c.end(),t);
		return *it;
	}
	if(c[0]>s){
		int g=c.back();
		c.pop_back();
		if(t>c.back()||t<s)return g;
		auto it=lower_bound(c.begin(),c.end(),t);
		return *it;
	}
	if(t<c[1]||t>s)return c[0];
	auto it=lower_bound(c.begin(),c.end(),t);
	if(it==c.end())return c.back();
	if(*it==t)return *it;
	it--;
	return *it;
	return c[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 924 KB Output is correct
2 Correct 259 ms 924 KB Output is correct
3 Correct 521 ms 684 KB Output is correct
4 Correct 377 ms 684 KB Output is correct
5 Correct 366 ms 684 KB Output is correct
6 Correct 263 ms 920 KB Output is correct
7 Correct 271 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 856 KB Output is correct
2 Correct 305 ms 788 KB Output is correct
3 Correct 490 ms 684 KB Output is correct
4 Correct 376 ms 684 KB Output is correct
5 Correct 327 ms 688 KB Output is correct
6 Correct 259 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 299 ms 932 KB Output is correct
2 Correct 259 ms 936 KB Output is correct
3 Correct 506 ms 684 KB Output is correct
4 Correct 403 ms 684 KB Output is correct
5 Correct 340 ms 684 KB Output is correct
6 Correct 266 ms 912 KB Output is correct
7 Correct 267 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 344 ms 684 KB Output is correct
12 Correct 265 ms 1628 KB Output is correct
13 Correct 268 ms 1184 KB Output is correct
14 Correct 238 ms 684 KB Output is correct
15 Correct 30 ms 732 KB Output is correct
16 Correct 40 ms 908 KB Output is correct
17 Correct 57 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 521 ms 936 KB Output is correct
2 Correct 372 ms 684 KB Output is correct
3 Correct 365 ms 684 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 3 ms 772 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 326 ms 684 KB Output is correct
8 Correct 510 ms 940 KB Output is correct
9 Correct 390 ms 684 KB Output is correct
10 Correct 343 ms 684 KB Output is correct
11 Correct 3 ms 768 KB Output is correct
12 Correct 3 ms 768 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 0 ms 764 KB Output is correct
16 Correct 290 ms 684 KB Output is correct
17 Correct 290 ms 684 KB Output is correct
18 Correct 278 ms 684 KB Output is correct
19 Correct 272 ms 684 KB Output is correct
20 Correct 282 ms 684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 924 KB Output is correct
2 Correct 240 ms 924 KB Output is correct
3 Correct 527 ms 684 KB Output is correct
4 Correct 411 ms 684 KB Output is correct
5 Correct 339 ms 684 KB Output is correct
6 Correct 270 ms 936 KB Output is correct
7 Correct 258 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 265 ms 864 KB Output is correct
12 Correct 315 ms 832 KB Output is correct
13 Correct 523 ms 880 KB Output is correct
14 Correct 388 ms 684 KB Output is correct
15 Correct 326 ms 684 KB Output is correct
16 Correct 241 ms 684 KB Output is correct
17 Correct 330 ms 684 KB Output is correct
18 Correct 281 ms 1236 KB Output is correct
19 Correct 259 ms 1268 KB Output is correct
20 Correct 252 ms 684 KB Output is correct
21 Correct 29 ms 768 KB Output is correct
22 Correct 34 ms 872 KB Output is correct
23 Correct 54 ms 1124 KB Output is correct
24 Correct 2 ms 768 KB Output is correct
25 Correct 3 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 1 ms 768 KB Output is correct
29 Correct 281 ms 1096 KB Output is correct
30 Correct 288 ms 684 KB Output is correct
31 Correct 294 ms 684 KB Output is correct
32 Correct 296 ms 684 KB Output is correct
33 Correct 298 ms 684 KB Output is correct
34 Correct 174 ms 900 KB Output is correct
35 Correct 242 ms 1144 KB Output is correct
36 Correct 251 ms 1176 KB Output is correct
37 Correct 267 ms 1120 KB Output is correct
38 Correct 252 ms 964 KB Output is correct
39 Correct 254 ms 1124 KB Output is correct
40 Correct 263 ms 1128 KB Output is correct
41 Correct 274 ms 1368 KB Output is correct
42 Correct 32 ms 844 KB Output is correct
43 Correct 58 ms 864 KB Output is correct
44 Correct 75 ms 860 KB Output is correct
45 Correct 100 ms 864 KB Output is correct
46 Correct 176 ms 860 KB Output is correct
47 Correct 158 ms 888 KB Output is correct
48 Correct 31 ms 1440 KB Output is correct
49 Correct 35 ms 1132 KB Output is correct