Submission #926945

# Submission time Handle Problem Language Result Execution time Memory
926945 2024-02-14T05:37:04 Z daoquanglinh2007 Stations (IOI20_stations) C++17
100 / 100
539 ms 1772 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

const int NM = 1000;
 
vector <int> adj[NM+5];
int dep[NM+5];
int timer = 0, tin[NM+5], tout[NM+5];
vector <int> arr;
 
void dfs(int u, int p){
	dep[u] = (p == -1 ? 0 : dep[p]+1);
	tin[u] = ++timer;
	for (int v : adj[u]){
		if (v == p) continue;
		dfs(v, u);
	}
	tout[u] = ++timer;
}
 
vector <int> label(int n, int k, vector <int> u, vector <int> v){
	for (int i = 0; i < n; i++) adj[i].clear();
	for (int i = 0; i < n-1; i++){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0, -1);
	arr.clear();
	for (int i = 0; i < n; i++){
		if (dep[i]&1) arr.push_back(tout[i]); else arr.push_back(tin[i]);
	}
	sort(arr.begin(), arr.end());
	vector <int> ans(n);
	for (int i = 0; i < n; i++){
		if (dep[i]&1) ans[i] = lower_bound(arr.begin(), arr.end(), tout[i])-arr.begin();
		else ans[i] = lower_bound(arr.begin(), arr.end(), tin[i])-arr.begin();
	}
	return ans;
}
 
int find_next_station(int s, int t, vector <int> c){
	if (s < c.front()){
		if (t < s || t > c.back()) return c.back();
		return c[lower_bound(c.begin(), c.end(), t)-c.begin()];
	}
	else{
		if (t < c.front() || t > s) return c.front();
		return c[--upper_bound(c.begin(), c.end(), t)-c.begin()];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 298 ms 912 KB Output is correct
2 Correct 268 ms 948 KB Output is correct
3 Correct 539 ms 684 KB Output is correct
4 Correct 430 ms 684 KB Output is correct
5 Correct 333 ms 684 KB Output is correct
6 Correct 258 ms 916 KB Output is correct
7 Correct 271 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 1376 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 884 KB Output is correct
2 Correct 299 ms 1072 KB Output is correct
3 Correct 499 ms 684 KB Output is correct
4 Correct 442 ms 684 KB Output is correct
5 Correct 402 ms 684 KB Output is correct
6 Correct 273 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 920 KB Output is correct
2 Correct 256 ms 920 KB Output is correct
3 Correct 529 ms 684 KB Output is correct
4 Correct 411 ms 884 KB Output is correct
5 Correct 353 ms 856 KB Output is correct
6 Correct 261 ms 904 KB Output is correct
7 Correct 273 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 375 ms 684 KB Output is correct
12 Correct 253 ms 984 KB Output is correct
13 Correct 251 ms 1424 KB Output is correct
14 Correct 258 ms 684 KB Output is correct
15 Correct 28 ms 768 KB Output is correct
16 Correct 46 ms 860 KB Output is correct
17 Correct 57 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 684 KB Output is correct
2 Correct 385 ms 684 KB Output is correct
3 Correct 355 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 1 ms 764 KB Output is correct
7 Correct 426 ms 684 KB Output is correct
8 Correct 522 ms 684 KB Output is correct
9 Correct 367 ms 684 KB Output is correct
10 Correct 315 ms 684 KB Output is correct
11 Correct 2 ms 764 KB Output is correct
12 Correct 3 ms 924 KB Output is correct
13 Correct 3 ms 768 KB Output is correct
14 Correct 3 ms 768 KB Output is correct
15 Correct 2 ms 768 KB Output is correct
16 Correct 285 ms 684 KB Output is correct
17 Correct 293 ms 684 KB Output is correct
18 Correct 284 ms 684 KB Output is correct
19 Correct 321 ms 684 KB Output is correct
20 Correct 313 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 928 KB Output is correct
2 Correct 276 ms 936 KB Output is correct
3 Correct 526 ms 684 KB Output is correct
4 Correct 400 ms 684 KB Output is correct
5 Correct 365 ms 684 KB Output is correct
6 Correct 270 ms 920 KB Output is correct
7 Correct 250 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 768 KB Output is correct
11 Correct 249 ms 1136 KB Output is correct
12 Correct 304 ms 852 KB Output is correct
13 Correct 539 ms 684 KB Output is correct
14 Correct 400 ms 876 KB Output is correct
15 Correct 340 ms 684 KB Output is correct
16 Correct 258 ms 684 KB Output is correct
17 Correct 403 ms 684 KB Output is correct
18 Correct 277 ms 1012 KB Output is correct
19 Correct 284 ms 1220 KB Output is correct
20 Correct 249 ms 684 KB Output is correct
21 Correct 33 ms 764 KB Output is correct
22 Correct 38 ms 884 KB Output is correct
23 Correct 63 ms 1132 KB Output is correct
24 Correct 3 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 0 ms 768 KB Output is correct
29 Correct 323 ms 796 KB Output is correct
30 Correct 303 ms 684 KB Output is correct
31 Correct 323 ms 684 KB Output is correct
32 Correct 321 ms 876 KB Output is correct
33 Correct 291 ms 684 KB Output is correct
34 Correct 179 ms 916 KB Output is correct
35 Correct 284 ms 1140 KB Output is correct
36 Correct 263 ms 1024 KB Output is correct
37 Correct 289 ms 1160 KB Output is correct
38 Correct 291 ms 1164 KB Output is correct
39 Correct 258 ms 1408 KB Output is correct
40 Correct 289 ms 1012 KB Output is correct
41 Correct 276 ms 1264 KB Output is correct
42 Correct 40 ms 1064 KB Output is correct
43 Correct 64 ms 936 KB Output is correct
44 Correct 85 ms 984 KB Output is correct
45 Correct 109 ms 900 KB Output is correct
46 Correct 195 ms 864 KB Output is correct
47 Correct 188 ms 888 KB Output is correct
48 Correct 31 ms 1772 KB Output is correct
49 Correct 32 ms 1236 KB Output is correct