Submission #815140

# Submission time Handle Problem Language Result Execution time Memory
815140 2023-08-08T12:39:13 Z oscar1f Stations (IOI20_stations) C++17
100 / 100
761 ms 944 KB
#include "stations.h"
#include<bits/stdc++.h>

using namespace std;

const int MAX_SOM=1005;
int dv[MAX_SOM];
vector<int> adja[MAX_SOM];
vector<int> ordre;

void DFS(int pos,int prof) {
	if (dv[pos]==0) {
		dv[pos]=1;
		if (prof%2==0) {
			ordre.push_back(pos);
		}
		for (int j:adja[pos]) {
			DFS(j,prof+1);
		}
		if (prof%2==1) {
			ordre.push_back(pos);
		}
	}
}

vector<int> label(int n,int k,vector<int> u,vector<int> v) {
	int nbSom=n;
	for (int i=0;i<nbSom;i++) {
		adja[i].clear();
		dv[i]=0;
	}
	ordre.clear();
	for (int i=0;i<nbSom-1;i++) {
		adja[u[i]].push_back(v[i]);
		adja[v[i]].push_back(u[i]);
	}
	DFS(0,0);
	vector<int> label(nbSom);
	for (int i=0;i<nbSom;i++) {
		label[ordre[i]]=i;
	}
	/*for (int i=0;i<nbSom;i++) {
		cout<<i<<" : "<<label[i]<<endl;
	}*/
	return label;
}

int find_next_station(int pos,int obj,vector<int> possi) {
	if (possi.size()==1) {
		return possi[0];
	}
	vector<int> inf,sup;
	for (int i:possi) {
		if (i<pos) {
			inf.push_back(i);
		}
		else {
			sup.push_back(i);
		}
	}
	if (pos==0) {
		for (int i:sup) {
			if (i>=obj) {
				return i;
			}
		}
	}
	if (inf.empty()) {
		for (int i=0;i<(int)sup.size()-1;i++) {
			if (sup[i]>=obj and pos<obj) {
				return sup[i];
			}
		}
		return sup.back();
	}
	else {
		for (int i=(int)inf.size()-1;i>0;i--) {
			if (inf[i]<=obj and pos>obj) {
				return inf[i];
			}
		}
		return inf[0];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 378 ms 664 KB Output is correct
2 Correct 393 ms 656 KB Output is correct
3 Correct 722 ms 532 KB Output is correct
4 Correct 607 ms 420 KB Output is correct
5 Correct 490 ms 528 KB Output is correct
6 Correct 420 ms 528 KB Output is correct
7 Correct 373 ms 528 KB Output is correct
8 Correct 2 ms 564 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 349 ms 524 KB Output is correct
2 Correct 411 ms 520 KB Output is correct
3 Correct 761 ms 552 KB Output is correct
4 Correct 560 ms 596 KB Output is correct
5 Correct 501 ms 528 KB Output is correct
6 Correct 428 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 660 KB Output is correct
2 Correct 338 ms 656 KB Output is correct
3 Correct 606 ms 524 KB Output is correct
4 Correct 532 ms 528 KB Output is correct
5 Correct 350 ms 432 KB Output is correct
6 Correct 399 ms 548 KB Output is correct
7 Correct 320 ms 528 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 423 ms 528 KB Output is correct
12 Correct 459 ms 780 KB Output is correct
13 Correct 362 ms 944 KB Output is correct
14 Correct 408 ms 524 KB Output is correct
15 Correct 46 ms 596 KB Output is correct
16 Correct 43 ms 728 KB Output is correct
17 Correct 74 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 739 ms 416 KB Output is correct
2 Correct 539 ms 532 KB Output is correct
3 Correct 450 ms 528 KB Output is correct
4 Correct 1 ms 556 KB Output is correct
5 Correct 5 ms 500 KB Output is correct
6 Correct 0 ms 492 KB Output is correct
7 Correct 406 ms 416 KB Output is correct
8 Correct 596 ms 640 KB Output is correct
9 Correct 475 ms 524 KB Output is correct
10 Correct 530 ms 528 KB Output is correct
11 Correct 5 ms 492 KB Output is correct
12 Correct 4 ms 536 KB Output is correct
13 Correct 3 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 1 ms 536 KB Output is correct
16 Correct 458 ms 416 KB Output is correct
17 Correct 495 ms 524 KB Output is correct
18 Correct 248 ms 552 KB Output is correct
19 Correct 457 ms 524 KB Output is correct
20 Correct 312 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 465 ms 548 KB Output is correct
2 Correct 299 ms 544 KB Output is correct
3 Correct 646 ms 416 KB Output is correct
4 Correct 599 ms 532 KB Output is correct
5 Correct 398 ms 532 KB Output is correct
6 Correct 356 ms 664 KB Output is correct
7 Correct 320 ms 548 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 0 ms 484 KB Output is correct
11 Correct 360 ms 528 KB Output is correct
12 Correct 389 ms 548 KB Output is correct
13 Correct 755 ms 548 KB Output is correct
14 Correct 609 ms 556 KB Output is correct
15 Correct 511 ms 544 KB Output is correct
16 Correct 319 ms 544 KB Output is correct
17 Correct 431 ms 524 KB Output is correct
18 Correct 352 ms 544 KB Output is correct
19 Correct 343 ms 776 KB Output is correct
20 Correct 288 ms 532 KB Output is correct
21 Correct 39 ms 544 KB Output is correct
22 Correct 62 ms 704 KB Output is correct
23 Correct 71 ms 672 KB Output is correct
24 Correct 4 ms 488 KB Output is correct
25 Correct 5 ms 492 KB Output is correct
26 Correct 4 ms 500 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 0 ms 500 KB Output is correct
29 Correct 340 ms 528 KB Output is correct
30 Correct 422 ms 528 KB Output is correct
31 Correct 348 ms 420 KB Output is correct
32 Correct 350 ms 532 KB Output is correct
33 Correct 395 ms 420 KB Output is correct
34 Correct 209 ms 544 KB Output is correct
35 Correct 406 ms 784 KB Output is correct
36 Correct 394 ms 672 KB Output is correct
37 Correct 349 ms 780 KB Output is correct
38 Correct 367 ms 664 KB Output is correct
39 Correct 328 ms 632 KB Output is correct
40 Correct 370 ms 632 KB Output is correct
41 Correct 370 ms 652 KB Output is correct
42 Correct 53 ms 672 KB Output is correct
43 Correct 111 ms 668 KB Output is correct
44 Correct 112 ms 620 KB Output is correct
45 Correct 153 ms 532 KB Output is correct
46 Correct 314 ms 544 KB Output is correct
47 Correct 204 ms 632 KB Output is correct
48 Correct 67 ms 672 KB Output is correct
49 Correct 37 ms 700 KB Output is correct