Submission #1067362

# Submission time Handle Problem Language Result Execution time Memory
1067362 2024-08-20T15:37:02 Z Lalic Stations (IOI20_stations) C++17
100 / 100
638 ms 1192 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(). x.rend()
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

const int INF = 0x3f3f3f3f;

void build(int ver, int prev, vector<int>& labels, bool isMax, int& cnt, vector<vector<int>>& adj, vector<int>& submin, vector<int>& submax){
	if(prev!=-1 && (int)adj[ver].size()==1){
		labels[ver]=cnt;
		submin[ver]=submax[ver]=cnt;
		cnt+=2000;
		return;
	}
	
	int mx=-INF, mn=INF;
	for(auto u : adj[ver]){
		if(u==prev) continue;
		build(u, ver, labels, !isMax, cnt, adj, submin, submax);
		mx=max(mx, submax[u]);
		mn=min(mn, submin[u]);
	}
	
	if(isMax){
		labels[ver]=submax[ver]=mx+1;
		submin[ver]=mn;
		if(mx+1>=cnt) cnt=mx+2;
	}
	else{
		labels[ver]=submin[ver]=mn-1;
		submax[ver]=mx;
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n);
	vector<vector<int>> adj(n);
	vector<int> submin(n), submax(n);
	
	for(int i=0;i<n-1;i++){
		adj[u[i]].pb(v[i]);
		adj[v[i]].pb(u[i]);
	}
	
	int aux=0;
	build(0, -1, labels, 0, aux, adj, submin, submax);
	
	vector<pii> proc;
	for(int i=0;i<n;i++) proc.pb({labels[i], i});
	
	sort(all(proc));
	
	//~ for(int i=0;i<n;i++) cout << labels[i] << " \n"[i==n-1];
	
	for(int i=0;i<n;i++) labels[proc[i].se]=i;
	
	//~ for(int i=0;i<n;i++) cout << labels[i] << " \n"[i==n-1];
	
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	sort(all(c));
	
	if(c[0]<s){
		if((int)c.size()==1 || t>s || t<c[1]) return c[0];
		for(int i=(int)c.size()-1;i>=0;i--)
			if(t>=c[i]) return c[i];
	}
	else{
		reverse(all(c));
		if((int)c.size()==1 || t<s || t>c[1]) return c[0];
		for(int i=(int)c.size()-1;i>=0;i--)
			if(t<=c[i]) return c[i];
	}
	
	return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 381 ms 940 KB Output is correct
2 Correct 316 ms 940 KB Output is correct
3 Correct 638 ms 696 KB Output is correct
4 Correct 478 ms 684 KB Output is correct
5 Correct 402 ms 684 KB Output is correct
6 Correct 305 ms 968 KB Output is correct
7 Correct 289 ms 940 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 288 ms 684 KB Output is correct
2 Correct 372 ms 684 KB Output is correct
3 Correct 571 ms 684 KB Output is correct
4 Correct 434 ms 684 KB Output is correct
5 Correct 433 ms 684 KB Output is correct
6 Correct 303 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 940 KB Output is correct
2 Correct 327 ms 940 KB Output is correct
3 Correct 638 ms 684 KB Output is correct
4 Correct 453 ms 684 KB Output is correct
5 Correct 376 ms 684 KB Output is correct
6 Correct 294 ms 944 KB Output is correct
7 Correct 294 ms 940 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 1 ms 776 KB Output is correct
11 Correct 391 ms 684 KB Output is correct
12 Correct 306 ms 1188 KB Output is correct
13 Correct 310 ms 1048 KB Output is correct
14 Correct 285 ms 684 KB Output is correct
15 Correct 26 ms 768 KB Output is correct
16 Correct 33 ms 764 KB Output is correct
17 Correct 67 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 940 KB Output is correct
2 Correct 458 ms 684 KB Output is correct
3 Correct 387 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 1 ms 776 KB Output is correct
6 Correct 0 ms 764 KB Output is correct
7 Correct 433 ms 688 KB Output is correct
8 Correct 608 ms 684 KB Output is correct
9 Correct 429 ms 684 KB Output is correct
10 Correct 404 ms 684 KB Output is correct
11 Correct 2 ms 764 KB Output is correct
12 Correct 2 ms 776 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 1 ms 764 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 331 ms 684 KB Output is correct
17 Correct 302 ms 684 KB Output is correct
18 Correct 301 ms 684 KB Output is correct
19 Correct 346 ms 688 KB Output is correct
20 Correct 343 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 940 KB Output is correct
2 Correct 300 ms 940 KB Output is correct
3 Correct 568 ms 684 KB Output is correct
4 Correct 464 ms 684 KB Output is correct
5 Correct 418 ms 684 KB Output is correct
6 Correct 296 ms 936 KB Output is correct
7 Correct 299 ms 940 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 1 ms 764 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 334 ms 684 KB Output is correct
12 Correct 348 ms 688 KB Output is correct
13 Correct 590 ms 684 KB Output is correct
14 Correct 494 ms 684 KB Output is correct
15 Correct 383 ms 688 KB Output is correct
16 Correct 307 ms 684 KB Output is correct
17 Correct 384 ms 684 KB Output is correct
18 Correct 294 ms 1040 KB Output is correct
19 Correct 300 ms 1012 KB Output is correct
20 Correct 303 ms 684 KB Output is correct
21 Correct 29 ms 764 KB Output is correct
22 Correct 34 ms 748 KB Output is correct
23 Correct 57 ms 696 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 3 ms 772 KB Output is correct
26 Correct 2 ms 776 KB Output is correct
27 Correct 1 ms 768 KB Output is correct
28 Correct 1 ms 776 KB Output is correct
29 Correct 333 ms 772 KB Output is correct
30 Correct 349 ms 696 KB Output is correct
31 Correct 368 ms 688 KB Output is correct
32 Correct 348 ms 684 KB Output is correct
33 Correct 332 ms 936 KB Output is correct
34 Correct 214 ms 1192 KB Output is correct
35 Correct 301 ms 1192 KB Output is correct
36 Correct 319 ms 1016 KB Output is correct
37 Correct 344 ms 684 KB Output is correct
38 Correct 356 ms 684 KB Output is correct
39 Correct 295 ms 764 KB Output is correct
40 Correct 323 ms 808 KB Output is correct
41 Correct 351 ms 932 KB Output is correct
42 Correct 27 ms 768 KB Output is correct
43 Correct 64 ms 768 KB Output is correct
44 Correct 85 ms 716 KB Output is correct
45 Correct 106 ms 684 KB Output is correct
46 Correct 209 ms 716 KB Output is correct
47 Correct 206 ms 940 KB Output is correct
48 Correct 32 ms 764 KB Output is correct
49 Correct 32 ms 1020 KB Output is correct