Submission #841346

# Submission time Handle Problem Language Result Execution time Memory
841346 2023-09-01T14:22:16 Z TheLostCookie Longest Trip (IOI23_longesttrip) C++17
85 / 100
15 ms 384 KB
#include "longesttrip.h"
#include <algorithm>
#include <numeric>
#include <vector>

std::vector<int> longest_trip(int N, int D) {
	std::vector<int> l0,l1;
	auto mergeLines = [&l0, &l1]()->void{
		while(!l1.empty()) {
			l0.push_back(l1.back());
			l1.pop_back();
		}
		return;
	};
	
	std::vector<int> p(N);
	std::iota(p.begin(),p.end(),0);
	std::srand(2023);
	std::random_shuffle(p.begin(),p.end());
	
	l0.push_back(p[0]);
	for(int i = 1; i < N; i++) {
		int u = p[i];
		if(l1.empty()) {
			(are_connected({l0.back()},{u})?l0:l1).push_back(u);
		} else {
			if(rand()%2) swap(l0,l1);
			if(!are_connected({l0.back()},{u})) {
				l1.push_back(u);
			} else {
				l0.push_back(u);
				if(are_connected({l1.back()},{u})) {
					mergeLines();
				}
			}
		}
	}
	
	if(l1.empty()) return l0;
	else if(!are_connected(l0,l1)) {
		if(l0.size()>l1.size()) return l0;
		else return l1;
	} else if(l0.size()>1&&(!are_connected({l0.front()},{l0.back()}))) {
		if(!are_connected({l0.back()},{l1.back()})) {
			std::reverse(l0.begin(),l0.end());
		}
		mergeLines();
		return l0;
	} else if(l1.size()>1&&(!are_connected({l1.front()},{l1.back()}))) {
		if(!are_connected({l0.back()},{l1.back()})) {
			std::reverse(l1.begin(),l1.end());
		}
		mergeLines();
		return l0;
	} else {
		std::vector<int> le(l0), ri(l1);
		for(int rep = 0; rep < 2; rep++) {
			while(le.size()>1) {
				std::vector<int> le0,le1;
				for(int i = 0; i < int(le.size()); i++) {
					(i%2?le0:le1).push_back(le[i]);
				}
				if(are_connected(le0,ri)) std::swap(le,le0);
				else std::swap(le,le1);
			}
			swap(le,ri);
		}
		int lei = 0, rii = 0;
		while(l0[lei] != le[0]) lei++;
		while(l1[rii] != ri[0]) rii++;
		
		std::vector<int> ans;
		for(int i = 0; i < int(l0.size()); i++) {
			ans.push_back(l0[(lei+i+1)%l0.size()]);
		}
		for(int i = 0; i < int(l1.size()); i++) {
			ans.push_back(l1[(rii+i)%l1.size()]);
		}
		return ans;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 10 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 9 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 14 ms 208 KB Output is correct
7 Correct 11 ms 208 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 8 ms 208 KB Output is correct
12 Correct 7 ms 288 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 7 ms 208 KB Output is correct
5 Correct 9 ms 208 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 7 ms 208 KB Output is correct
9 Correct 6 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 6 ms 208 KB Output is correct
12 Correct 7 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 14 ms 208 KB Output is correct
15 Correct 10 ms 208 KB Output is correct
16 Correct 13 ms 208 KB Output is correct
17 Correct 13 ms 208 KB Output is correct
18 Correct 8 ms 208 KB Output is correct
19 Correct 6 ms 332 KB Output is correct
20 Correct 8 ms 208 KB Output is correct
21 Correct 8 ms 208 KB Output is correct
22 Correct 4 ms 208 KB Output is correct
23 Correct 9 ms 208 KB Output is correct
24 Correct 7 ms 208 KB Output is correct
25 Correct 11 ms 208 KB Output is correct
26 Correct 8 ms 208 KB Output is correct
27 Correct 9 ms 208 KB Output is correct
28 Correct 10 ms 208 KB Output is correct
29 Correct 10 ms 208 KB Output is correct
30 Correct 7 ms 208 KB Output is correct
31 Correct 12 ms 208 KB Output is correct
32 Correct 10 ms 208 KB Output is correct
33 Correct 9 ms 256 KB Output is correct
34 Correct 9 ms 208 KB Output is correct
35 Correct 9 ms 208 KB Output is correct
36 Correct 11 ms 208 KB Output is correct
37 Correct 10 ms 208 KB Output is correct
38 Correct 10 ms 208 KB Output is correct
39 Correct 10 ms 332 KB Output is correct
40 Correct 10 ms 208 KB Output is correct
41 Correct 13 ms 208 KB Output is correct
42 Correct 8 ms 208 KB Output is correct
43 Correct 14 ms 208 KB Output is correct
44 Correct 10 ms 332 KB Output is correct
45 Correct 11 ms 208 KB Output is correct
46 Correct 11 ms 208 KB Output is correct
47 Correct 14 ms 208 KB Output is correct
48 Correct 12 ms 208 KB Output is correct
49 Correct 14 ms 208 KB Output is correct
50 Correct 9 ms 208 KB Output is correct
51 Correct 12 ms 276 KB Output is correct
52 Correct 12 ms 260 KB Output is correct
53 Correct 9 ms 208 KB Output is correct
54 Correct 10 ms 208 KB Output is correct
55 Correct 9 ms 208 KB Output is correct
56 Correct 8 ms 208 KB Output is correct
57 Correct 10 ms 208 KB Output is correct
58 Correct 11 ms 208 KB Output is correct
59 Correct 13 ms 384 KB Output is correct
60 Correct 12 ms 208 KB Output is correct
61 Correct 15 ms 208 KB Output is correct
62 Correct 10 ms 208 KB Output is correct
63 Correct 12 ms 208 KB Output is correct
64 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 9 ms 208 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 11 ms 208 KB Output is correct
7 Correct 7 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 6 ms 208 KB Output is correct
11 Correct 6 ms 208 KB Output is correct
12 Correct 8 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 11 ms 208 KB Output is correct
15 Correct 9 ms 208 KB Output is correct
16 Correct 11 ms 208 KB Output is correct
17 Correct 11 ms 208 KB Output is correct
18 Correct 10 ms 208 KB Output is correct
19 Correct 10 ms 208 KB Output is correct
20 Correct 8 ms 208 KB Output is correct
21 Correct 10 ms 208 KB Output is correct
22 Correct 9 ms 208 KB Output is correct
23 Correct 10 ms 208 KB Output is correct
24 Correct 10 ms 208 KB Output is correct
25 Correct 9 ms 208 KB Output is correct
26 Correct 12 ms 208 KB Output is correct
27 Correct 13 ms 208 KB Output is correct
28 Correct 7 ms 208 KB Output is correct
29 Correct 9 ms 208 KB Output is correct
30 Correct 9 ms 208 KB Output is correct
31 Correct 10 ms 208 KB Output is correct
32 Correct 11 ms 208 KB Output is correct
33 Correct 11 ms 208 KB Output is correct
34 Correct 10 ms 208 KB Output is correct
35 Correct 12 ms 208 KB Output is correct
36 Correct 12 ms 208 KB Output is correct
37 Correct 9 ms 208 KB Output is correct
38 Correct 14 ms 256 KB Output is correct
39 Correct 12 ms 208 KB Output is correct
40 Correct 11 ms 208 KB Output is correct
41 Correct 13 ms 208 KB Output is correct
42 Correct 12 ms 208 KB Output is correct
43 Correct 10 ms 208 KB Output is correct
44 Correct 7 ms 208 KB Output is correct
45 Correct 7 ms 208 KB Output is correct
46 Correct 7 ms 292 KB Output is correct
47 Correct 8 ms 208 KB Output is correct
48 Correct 11 ms 208 KB Output is correct
49 Correct 9 ms 208 KB Output is correct
50 Correct 12 ms 208 KB Output is correct
51 Correct 13 ms 208 KB Output is correct
52 Correct 7 ms 208 KB Output is correct
53 Correct 9 ms 208 KB Output is correct
54 Partially correct 12 ms 208 KB Output is partially correct
55 Correct 10 ms 208 KB Output is correct
56 Correct 12 ms 208 KB Output is correct
57 Correct 13 ms 208 KB Output is correct
58 Correct 11 ms 208 KB Output is correct
59 Correct 11 ms 208 KB Output is correct
60 Correct 12 ms 208 KB Output is correct
61 Correct 8 ms 208 KB Output is correct
62 Correct 8 ms 288 KB Output is correct
63 Correct 10 ms 208 KB Output is correct
64 Correct 13 ms 208 KB Output is correct
65 Partially correct 10 ms 208 KB Output is partially correct
66 Partially correct 8 ms 292 KB Output is partially correct
67 Partially correct 13 ms 208 KB Output is partially correct
68 Partially correct 11 ms 208 KB Output is partially correct
69 Correct 11 ms 256 KB Output is correct
70 Partially correct 11 ms 208 KB Output is partially correct
71 Partially correct 12 ms 292 KB Output is partially correct
72 Partially correct 6 ms 292 KB Output is partially correct
73 Partially correct 9 ms 208 KB Output is partially correct
74 Partially correct 11 ms 208 KB Output is partially correct
75 Partially correct 11 ms 292 KB Output is partially correct
76 Partially correct 9 ms 208 KB Output is partially correct
77 Correct 10 ms 208 KB Output is correct
78 Correct 12 ms 280 KB Output is correct
79 Partially correct 12 ms 208 KB Output is partially correct
80 Partially correct 10 ms 208 KB Output is partially correct
81 Partially correct 11 ms 288 KB Output is partially correct
82 Correct 13 ms 208 KB Output is correct