Submission #840245

# Submission time Handle Problem Language Result Execution time Memory
840245 2023-08-31T08:40:03 Z TranGiaHuy1508 Longest Trip (IOI23_longesttrip) C++17
85 / 100
18 ms 428 KB
#include <bits/stdc++.h>
using namespace std;

#include "longesttrip.h"

vector<int> subrange(vector<int> &V, int l, int r){
	vector<int> res(V.begin() + l, V.begin() + r + 1);
	return res;
}

vector<int> longest_trip(int N, int D){
	// Assuming D = 1

	vector<int> v1 = {0}, v2 = {1};
	bool stupid = false;

	for (int i = 2; i < N; i++){
		if (are_connected({v1.back()}, {i})){
			v1.push_back(i);
			// stupid = false;
		}
		else if (/*!stupid && */are_connected({v2.back()}, {i})){
			v2.push_back(i);
			// stupid = true;
		}
		else{
			reverse(v2.begin(), v2.end());
			v1.insert(v1.end(), v2.begin(), v2.end());
			v2.clear(); v2.push_back(i);
			// stupid = false;
		}
	}

	bool bruh = false;
	if (v1.front() != v1.back() && !are_connected({v1.front()}, {v1.back()})) bruh = true;
	if (v2.front() != v2.back() && !are_connected({v2.front()}, {v2.back()})) bruh = true;
	
	if (bruh){
		if (are_connected({v1.front()}, {v2.front()})){
			reverse(v1.begin(), v1.end());
			v1.insert(v1.end(), v2.begin(), v2.end());
			return v1;
		}
		if (are_connected({v1.back()}, {v2.front()})){
			v1.insert(v1.end(), v2.begin(), v2.end());
			return v1;
		}
		if (are_connected({v1.front()}, {v2.back()})){
			v2.insert(v2.end(), v1.begin(), v1.end());
			return v2;
		}
		if (are_connected({v1.back()}, {v2.back()})){
			reverse(v1.begin(), v1.end());
			v2.insert(v2.end(), v1.begin(), v1.end());
			return v2;
		}
	}

	if (!are_connected(v1, v2)){
		if (v1.size() > v2.size()) return v1;
		return v2;
	}

	int l1 = 0, r1 = v1.size() - 1;
	int l2 = 0, r2 = v2.size() - 1;

	while (l1 < r1){
		int mid = (l1 + r1) >> 1;
		bool edge = are_connected(subrange(v1, l1, mid), subrange(v2, l2, r2));
		if (edge) r1 = mid;
		else l1 = mid + 1;
	}

	while (l2 < r2){
		int mid = (l2 + r2) >> 1;
		bool edge = are_connected(subrange(v1, l1, r1), subrange(v2, l2, mid));
		if (edge) r2 = mid;
		else l2 = mid + 1;
	}

	vector<int> res1, res2;
	for (int i = l1; i < (int)v1.size(); i++) res1.push_back(v1[i]);
	for (int i = 0; i < l1; i++) res1.push_back(v1[i]);
	for (int i = l2; i < (int)v2.size(); i++) res2.push_back(v2[i]);
	for (int i = 0; i < l2; i++) res2.push_back(v2[i]);

	reverse(res1.begin(), res1.end());
	res2.insert(res2.begin(), res1.begin(), res1.end());
	return res2;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:15:7: warning: unused variable 'stupid' [-Wunused-variable]
   15 |  bool stupid = false;
      |       ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 13 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 9 ms 288 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 11 ms 208 KB Output is correct
4 Correct 11 ms 208 KB Output is correct
5 Correct 10 ms 296 KB Output is correct
6 Correct 8 ms 208 KB Output is correct
7 Correct 8 ms 256 KB Output is correct
8 Correct 12 ms 208 KB Output is correct
9 Correct 5 ms 208 KB Output is correct
10 Correct 8 ms 300 KB Output is correct
11 Correct 10 ms 300 KB Output is correct
12 Correct 10 ms 208 KB Output is correct
13 Correct 11 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 208 KB Output is correct
2 Correct 14 ms 208 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 7 ms 300 KB Output is correct
5 Correct 9 ms 300 KB Output is correct
6 Correct 15 ms 208 KB Output is correct
7 Correct 14 ms 208 KB Output is correct
8 Correct 11 ms 208 KB Output is correct
9 Correct 9 ms 208 KB Output is correct
10 Correct 5 ms 208 KB Output is correct
11 Correct 7 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 15 ms 208 KB Output is correct
15 Correct 16 ms 208 KB Output is correct
16 Correct 16 ms 288 KB Output is correct
17 Correct 13 ms 300 KB Output is correct
18 Correct 9 ms 208 KB Output is correct
19 Correct 13 ms 300 KB Output is correct
20 Correct 11 ms 208 KB Output is correct
21 Correct 12 ms 300 KB Output is correct
22 Correct 6 ms 428 KB Output is correct
23 Correct 8 ms 208 KB Output is correct
24 Correct 11 ms 208 KB Output is correct
25 Correct 13 ms 208 KB Output is correct
26 Correct 14 ms 208 KB Output is correct
27 Correct 9 ms 208 KB Output is correct
28 Correct 11 ms 208 KB Output is correct
29 Correct 12 ms 208 KB Output is correct
30 Correct 9 ms 208 KB Output is correct
31 Correct 11 ms 208 KB Output is correct
32 Correct 13 ms 208 KB Output is correct
33 Correct 9 ms 208 KB Output is correct
34 Correct 8 ms 208 KB Output is correct
35 Correct 10 ms 208 KB Output is correct
36 Correct 7 ms 296 KB Output is correct
37 Correct 7 ms 208 KB Output is correct
38 Correct 10 ms 208 KB Output is correct
39 Correct 9 ms 300 KB Output is correct
40 Correct 9 ms 208 KB Output is correct
41 Correct 14 ms 208 KB Output is correct
42 Correct 11 ms 208 KB Output is correct
43 Correct 11 ms 300 KB Output is correct
44 Correct 13 ms 208 KB Output is correct
45 Correct 16 ms 208 KB Output is correct
46 Correct 18 ms 208 KB Output is correct
47 Correct 11 ms 208 KB Output is correct
48 Correct 15 ms 208 KB Output is correct
49 Correct 12 ms 208 KB Output is correct
50 Correct 10 ms 208 KB Output is correct
51 Correct 13 ms 308 KB Output is correct
52 Correct 11 ms 208 KB Output is correct
53 Correct 10 ms 208 KB Output is correct
54 Correct 10 ms 296 KB Output is correct
55 Correct 12 ms 208 KB Output is correct
56 Correct 7 ms 300 KB Output is correct
57 Correct 10 ms 208 KB Output is correct
58 Correct 13 ms 296 KB Output is correct
59 Correct 11 ms 208 KB Output is correct
60 Correct 10 ms 208 KB Output is correct
61 Correct 10 ms 208 KB Output is correct
62 Correct 13 ms 208 KB Output is correct
63 Correct 16 ms 208 KB Output is correct
64 Correct 12 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 208 KB Output is correct
2 Correct 11 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 10 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 12 ms 208 KB Output is correct
8 Correct 10 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 8 ms 208 KB Output is correct
11 Correct 10 ms 208 KB Output is correct
12 Correct 11 ms 208 KB Output is correct
13 Correct 7 ms 208 KB Output is correct
14 Correct 15 ms 208 KB Output is correct
15 Correct 16 ms 208 KB Output is correct
16 Correct 16 ms 208 KB Output is correct
17 Correct 6 ms 208 KB Output is correct
18 Correct 6 ms 304 KB Output is correct
19 Correct 12 ms 208 KB Output is correct
20 Correct 9 ms 236 KB Output is correct
21 Correct 11 ms 208 KB Output is correct
22 Correct 16 ms 208 KB Output is correct
23 Correct 6 ms 208 KB Output is correct
24 Correct 9 ms 208 KB Output is correct
25 Correct 12 ms 208 KB Output is correct
26 Correct 9 ms 208 KB Output is correct
27 Correct 11 ms 208 KB Output is correct
28 Correct 12 ms 208 KB Output is correct
29 Correct 11 ms 224 KB Output is correct
30 Correct 6 ms 208 KB Output is correct
31 Correct 7 ms 208 KB Output is correct
32 Correct 16 ms 208 KB Output is correct
33 Correct 18 ms 208 KB Output is correct
34 Correct 14 ms 208 KB Output is correct
35 Correct 10 ms 208 KB Output is correct
36 Correct 7 ms 208 KB Output is correct
37 Correct 9 ms 208 KB Output is correct
38 Correct 16 ms 300 KB Output is correct
39 Correct 10 ms 208 KB Output is correct
40 Correct 10 ms 208 KB Output is correct
41 Correct 9 ms 208 KB Output is correct
42 Correct 9 ms 208 KB Output is correct
43 Correct 8 ms 308 KB Output is correct
44 Correct 11 ms 208 KB Output is correct
45 Correct 10 ms 308 KB Output is correct
46 Correct 10 ms 208 KB Output is correct
47 Correct 10 ms 208 KB Output is correct
48 Correct 6 ms 208 KB Output is correct
49 Correct 8 ms 208 KB Output is correct
50 Correct 10 ms 208 KB Output is correct
51 Partially correct 13 ms 208 KB Output is partially correct
52 Correct 10 ms 208 KB Output is correct
53 Correct 13 ms 208 KB Output is correct
54 Correct 14 ms 208 KB Output is correct
55 Correct 14 ms 208 KB Output is correct
56 Correct 7 ms 208 KB Output is correct
57 Partially correct 12 ms 208 KB Output is partially correct
58 Partially correct 13 ms 208 KB Output is partially correct
59 Partially correct 14 ms 208 KB Output is partially correct
60 Correct 9 ms 208 KB Output is correct
61 Correct 14 ms 288 KB Output is correct
62 Correct 10 ms 208 KB Output is correct
63 Partially correct 12 ms 208 KB Output is partially correct
64 Partially correct 14 ms 288 KB Output is partially correct
65 Partially correct 13 ms 208 KB Output is partially correct
66 Partially correct 13 ms 208 KB Output is partially correct
67 Correct 10 ms 284 KB Output is correct
68 Correct 9 ms 208 KB Output is correct
69 Partially correct 15 ms 208 KB Output is partially correct
70 Partially correct 13 ms 208 KB Output is partially correct
71 Correct 8 ms 300 KB Output is correct
72 Partially correct 13 ms 208 KB Output is partially correct
73 Partially correct 9 ms 208 KB Output is partially correct
74 Partially correct 14 ms 208 KB Output is partially correct
75 Correct 14 ms 208 KB Output is correct
76 Correct 12 ms 208 KB Output is correct
77 Correct 10 ms 300 KB Output is correct
78 Partially correct 9 ms 208 KB Output is partially correct
79 Correct 13 ms 296 KB Output is correct
80 Partially correct 14 ms 284 KB Output is partially correct
81 Correct 10 ms 208 KB Output is correct
82 Correct 14 ms 208 KB Output is correct