Submission #987311

# Submission time Handle Problem Language Result Execution time Memory
987311 2024-05-22T14:35:38 Z aaaaaarroz Stations (IOI20_stations) C++17
100 / 100
591 ms 1704 KB
    #include "stations.h"
    #include<bits/stdc++.h>
    using namespace std;
    vector<int>adj[1000];
    int tin[1000],tout[1000],color[1000];
    int timer = -1;
    void dfs(int v,int u){
    	tin[v] = ++timer;
    	for(int x:adj[v]){
    		if(x==u)continue;
    		color[x] = color[v]^1;
    		dfs(x,v);
    	}
    	tout[v] = ++timer;
    }
    vector<int> label(int n, int k, vector<int> u, vector<int> v) {
    	for(int i=0;i<n;i++)adj[i].clear();
    	vector<int>lab(n);
    	for(int i=0;i+1<n;i++){
    		adj[v[i]].push_back(u[i]);
    		adj[u[i]].push_back(v[i]);
    	}
     
    	timer = -1;
    	dfs(0,-1);
    	for(int i=0;i<n;i++){
    		if(color[i])lab[i] = tin[i];
    		else lab[i] = tout[i];
    	} 
    	vector<int>crd;
    	for(int x:lab)crd.push_back(x);
    	sort(crd.begin(),crd.end());
    	crd.resize(unique(crd.begin(),crd.end()) - crd.begin());
    	for(int &x:lab)x = lower_bound(crd.begin(),crd.end(),x) - crd.begin();
    	return lab;
    }
     
    int find_next_station(int s, int t, vector<int> c) {
    	int n = c.size();
    	if(c.back() > s){ 
    		//s label is tin
    		int last = s;
    		for(int i=0;i+1<n;i++){
    			int l = last+1;
    			int r = c[i];
    			if(l <= t && t <= r)return c[i];
    			last = c[i];
    		} 
    		return c.back();
    	}else{
    		//s label is tout
    		int last = s;
    		for(int i=n-1;i>0;i--){
    			int l = c[i];
    			int r = last-1;
    			if(l <= t && t <= r)return c[i];
    			last = c[i];
    		}
    		return c[0];
    	}
    }
# Verdict Execution time Memory Grader output
1 Correct 334 ms 928 KB Output is correct
2 Correct 263 ms 924 KB Output is correct
3 Correct 536 ms 684 KB Output is correct
4 Correct 415 ms 684 KB Output is correct
5 Correct 369 ms 684 KB Output is correct
6 Correct 333 ms 916 KB Output is correct
7 Correct 266 ms 684 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 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 1124 KB Output is correct
2 Correct 347 ms 824 KB Output is correct
3 Correct 565 ms 684 KB Output is correct
4 Correct 429 ms 680 KB Output is correct
5 Correct 389 ms 684 KB Output is correct
6 Correct 252 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 399 ms 932 KB Output is correct
2 Correct 301 ms 932 KB Output is correct
3 Correct 546 ms 684 KB Output is correct
4 Correct 439 ms 688 KB Output is correct
5 Correct 341 ms 684 KB Output is correct
6 Correct 273 ms 908 KB Output is correct
7 Correct 293 ms 684 KB Output is correct
8 Correct 2 ms 768 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 2 ms 764 KB Output is correct
11 Correct 384 ms 684 KB Output is correct
12 Correct 320 ms 980 KB Output is correct
13 Correct 314 ms 1288 KB Output is correct
14 Correct 281 ms 684 KB Output is correct
15 Correct 31 ms 768 KB Output is correct
16 Correct 39 ms 920 KB Output is correct
17 Correct 62 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 591 ms 684 KB Output is correct
2 Correct 493 ms 684 KB Output is correct
3 Correct 349 ms 684 KB Output is correct
4 Correct 2 ms 768 KB Output is correct
5 Correct 3 ms 760 KB Output is correct
6 Correct 2 ms 768 KB Output is correct
7 Correct 342 ms 848 KB Output is correct
8 Correct 548 ms 684 KB Output is correct
9 Correct 434 ms 684 KB Output is correct
10 Correct 423 ms 684 KB Output is correct
11 Correct 4 ms 768 KB Output is correct
12 Correct 4 ms 768 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 379 ms 684 KB Output is correct
17 Correct 304 ms 684 KB Output is correct
18 Correct 330 ms 684 KB Output is correct
19 Correct 311 ms 684 KB Output is correct
20 Correct 307 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 1104 KB Output is correct
2 Correct 325 ms 924 KB Output is correct
3 Correct 558 ms 684 KB Output is correct
4 Correct 422 ms 868 KB Output is correct
5 Correct 377 ms 684 KB Output is correct
6 Correct 259 ms 928 KB Output is correct
7 Correct 261 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 760 KB Output is correct
10 Correct 1 ms 764 KB Output is correct
11 Correct 298 ms 872 KB Output is correct
12 Correct 384 ms 856 KB Output is correct
13 Correct 589 ms 684 KB Output is correct
14 Correct 412 ms 684 KB Output is correct
15 Correct 389 ms 684 KB Output is correct
16 Correct 286 ms 684 KB Output is correct
17 Correct 358 ms 684 KB Output is correct
18 Correct 295 ms 1160 KB Output is correct
19 Correct 305 ms 1288 KB Output is correct
20 Correct 259 ms 684 KB Output is correct
21 Correct 33 ms 736 KB Output is correct
22 Correct 44 ms 904 KB Output is correct
23 Correct 67 ms 876 KB Output is correct
24 Correct 4 ms 768 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 3 ms 768 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 2 ms 768 KB Output is correct
29 Correct 314 ms 684 KB Output is correct
30 Correct 311 ms 720 KB Output is correct
31 Correct 319 ms 684 KB Output is correct
32 Correct 328 ms 684 KB Output is correct
33 Correct 332 ms 684 KB Output is correct
34 Correct 187 ms 932 KB Output is correct
35 Correct 291 ms 1196 KB Output is correct
36 Correct 291 ms 1040 KB Output is correct
37 Correct 300 ms 1168 KB Output is correct
38 Correct 286 ms 1164 KB Output is correct
39 Correct 294 ms 1276 KB Output is correct
40 Correct 311 ms 1276 KB Output is correct
41 Correct 269 ms 1272 KB Output is correct
42 Correct 35 ms 876 KB Output is correct
43 Correct 62 ms 1128 KB Output is correct
44 Correct 84 ms 896 KB Output is correct
45 Correct 127 ms 904 KB Output is correct
46 Correct 189 ms 876 KB Output is correct
47 Correct 195 ms 904 KB Output is correct
48 Correct 40 ms 1436 KB Output is correct
49 Correct 34 ms 1704 KB Output is correct