Submission #1010948

# Submission time Handle Problem Language Result Execution time Memory
1010948 2024-06-29T14:54:40 Z thangdz2k7 Longest Trip (IOI23_longesttrip) C++17
100 / 100
11 ms 696 KB
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector <int> vec;
#define q are_connected
#define pb push_back
vec a, b; int p[256];
void app() {
	for (int i : b) a. pb(i);
	b. clear();
}
vec longest_trip(int n, int d) {
	srand(114);
	for (int i=0; i<n; i++) p[i] = i;
	random_shuffle (p, p+n);
	a = vec {p[0]}, b = vec {p[1]};
	bool f = 0;
	for (int _=2; _<n; _++) {
		int i = p[_];
		if (q({a. back()}, {i})) a. pb(i), f = 0;
		else if (f || q({b. back()}, {i})) b. pb(i), f = 1;
		else reverse (b. begin(), b. end()), app(), b. pb(i);
	}
	if (b. empty()) return a;
	if (! q(a, b)) return a. size() > b. size() ? a : b;
	if (! f && q({a. back()}, {b. back()})) return reverse (b. begin(), b. end()), app(), a;
	if (q({a. back()}, b)) {
		int l = 0, r = b. size() - 2;
		while (l < r) {
			int mid = l + r >> 1;
			if (q({a. back()}, vec (b. begin(), b. begin() + mid + 1))) r = mid;
			else l = mid + 1;
		} return rotate (b. begin(), b. begin() + r, b. end()), app(), a;
	} else {
		int l = 0, r = a. size() - 2;
		while (l < r) {
			int mid = l + r >> 1;
			if (q(vec (a. begin(), a. begin() + mid + 1), b)) r = mid;
			else l = mid + 1;
		} r ? rotate (a. begin(), a. begin() + r + 1, a. end()), void () : reverse (a. begin(), a. end());
		l = 0, r = b. size() - 1;
		while (l < r) {
			int mid = l + r >> 1;
			if (q({a. back()}, vec (b. begin(), b. begin() + mid + 1))) r = mid;
			else l = mid + 1;
		} return rotate (b. begin(), b. begin() + r, b. end()), app(), a;
	}
}

Compilation message

longesttrip.cpp: In function 'vec longest_trip(int, int)':
longesttrip.cpp:30:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |    int mid = l + r >> 1;
      |              ~~^~~
longesttrip.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |    int mid = l + r >> 1;
      |              ~~^~~
longesttrip.cpp:43:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |    int mid = l + r >> 1;
      |              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 6 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 6 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 6 ms 344 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Correct 5 ms 344 KB Output is correct
11 Correct 7 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 7 ms 344 KB Output is correct
16 Correct 7 ms 596 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 8 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 7 ms 344 KB Output is correct
24 Correct 5 ms 344 KB Output is correct
25 Correct 5 ms 344 KB Output is correct
26 Correct 10 ms 344 KB Output is correct
27 Correct 7 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 5 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 5 ms 344 KB Output is correct
34 Correct 7 ms 344 KB Output is correct
35 Correct 5 ms 344 KB Output is correct
36 Correct 7 ms 344 KB Output is correct
37 Correct 5 ms 600 KB Output is correct
38 Correct 8 ms 440 KB Output is correct
39 Correct 5 ms 344 KB Output is correct
40 Correct 10 ms 344 KB Output is correct
41 Correct 9 ms 344 KB Output is correct
42 Correct 7 ms 344 KB Output is correct
43 Correct 7 ms 344 KB Output is correct
44 Correct 6 ms 344 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 8 ms 344 KB Output is correct
48 Correct 10 ms 344 KB Output is correct
49 Correct 9 ms 344 KB Output is correct
50 Correct 6 ms 340 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 10 ms 344 KB Output is correct
53 Correct 8 ms 344 KB Output is correct
54 Correct 5 ms 344 KB Output is correct
55 Correct 6 ms 344 KB Output is correct
56 Correct 5 ms 344 KB Output is correct
57 Correct 5 ms 344 KB Output is correct
58 Correct 6 ms 344 KB Output is correct
59 Correct 9 ms 344 KB Output is correct
60 Correct 9 ms 344 KB Output is correct
61 Correct 6 ms 696 KB Output is correct
62 Correct 7 ms 344 KB Output is correct
63 Correct 9 ms 340 KB Output is correct
64 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 8 ms 344 KB Output is correct
7 Correct 9 ms 344 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 5 ms 428 KB Output is correct
11 Correct 5 ms 344 KB Output is correct
12 Correct 5 ms 344 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 344 KB Output is correct
15 Correct 7 ms 340 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 7 ms 344 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 6 ms 344 KB Output is correct
21 Correct 7 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 5 ms 344 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 8 ms 344 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 8 ms 344 KB Output is correct
28 Correct 7 ms 344 KB Output is correct
29 Correct 6 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 5 ms 344 KB Output is correct
32 Correct 8 ms 344 KB Output is correct
33 Correct 9 ms 344 KB Output is correct
34 Correct 8 ms 344 KB Output is correct
35 Correct 11 ms 344 KB Output is correct
36 Correct 8 ms 344 KB Output is correct
37 Correct 6 ms 344 KB Output is correct
38 Correct 7 ms 344 KB Output is correct
39 Correct 7 ms 600 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 6 ms 344 KB Output is correct
42 Correct 6 ms 344 KB Output is correct
43 Correct 6 ms 344 KB Output is correct
44 Correct 8 ms 344 KB Output is correct
45 Correct 5 ms 444 KB Output is correct
46 Correct 6 ms 600 KB Output is correct
47 Correct 5 ms 344 KB Output is correct
48 Correct 6 ms 344 KB Output is correct
49 Correct 7 ms 600 KB Output is correct
50 Correct 7 ms 444 KB Output is correct
51 Correct 6 ms 344 KB Output is correct
52 Correct 7 ms 344 KB Output is correct
53 Correct 8 ms 344 KB Output is correct
54 Correct 7 ms 596 KB Output is correct
55 Correct 7 ms 344 KB Output is correct
56 Correct 7 ms 344 KB Output is correct
57 Correct 5 ms 344 KB Output is correct
58 Correct 8 ms 344 KB Output is correct
59 Correct 7 ms 344 KB Output is correct
60 Correct 7 ms 344 KB Output is correct
61 Correct 8 ms 344 KB Output is correct
62 Correct 7 ms 600 KB Output is correct
63 Correct 6 ms 344 KB Output is correct
64 Correct 6 ms 344 KB Output is correct
65 Correct 6 ms 600 KB Output is correct
66 Correct 9 ms 592 KB Output is correct
67 Correct 11 ms 436 KB Output is correct
68 Correct 7 ms 344 KB Output is correct
69 Correct 9 ms 344 KB Output is correct
70 Correct 9 ms 600 KB Output is correct
71 Correct 6 ms 344 KB Output is correct
72 Correct 8 ms 344 KB Output is correct
73 Correct 8 ms 600 KB Output is correct
74 Correct 7 ms 344 KB Output is correct
75 Correct 5 ms 344 KB Output is correct
76 Correct 11 ms 344 KB Output is correct
77 Correct 7 ms 344 KB Output is correct
78 Correct 6 ms 428 KB Output is correct
79 Correct 7 ms 344 KB Output is correct
80 Correct 7 ms 344 KB Output is correct
81 Correct 5 ms 344 KB Output is correct
82 Correct 9 ms 344 KB Output is correct