#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
deque<int> haha[500];
int n;
void merge(int a, int b) {
for(int i = 0; i < haha[b].size(); i++) {
haha[a].push_front(haha[b][i]);
}
haha[b].clear();
}
int dude(int p1, int p2, int y) {
vector<int> a(0);
vector<int> b(0);
if(y == -1) {
for(int i = 0; i < haha[p2].size(); i++) {
b.push_back(haha[p2][i]);
}
}
else {
b.push_back(haha[p2][y]);
}
int l = 0,r = haha[p1].size()-1;
while(l < r) {
int m = (l+r)/2;
a.clear();
for(int i = l; i <= m; i++) {
a.push_back(haha[p1][i]);
}
if(are_connected(a,b)) {
r = m;
}
else {
l = m+1;
}
}
return l;
}
std::vector<int> longest_trip(int N, int D)
{
n = N;
for(int i = 0; i < n; i++) {
haha[i].clear();
haha[i].push_back(i);
}
for(int i = 0; i < n-2; i++) {
vector<int> wut(0);
for(int j = 0; j < n; j++) {
if(haha[j].size() > 0) {
wut.push_back(j);
if(wut.size() == 3) {
break;
}
}
}
if(are_connected({haha[wut[0]][0]},{haha[wut[1]][0]})) {
merge(wut[0],wut[1]);
}
else if(are_connected({haha[wut[0]][0]},{haha[wut[2]][0]})) {
merge(wut[0],wut[2]);
}
else {
merge(wut[1],wut[2]);
}
}
int p1 = -1,p2;
for(int i = 0; i < n; i++) {
if(haha[i].size() > 0) {
if(p1 == -1) {
p1 = i;
}
else {
p2 = i;
}
}
}
vector<int> ans(0);
if(are_connected({haha[p1][0]},{haha[p2][0]})) {
for(int i = haha[p1].size()-1; i >= 0; i--) {
ans.push_back(haha[p1][i]);
}
for(int i = 0; i < haha[p2].size(); i++) {
ans.push_back(haha[p2][i]);
}
return ans;
}
if(are_connected({haha[p1][haha[p1].size()-1]},{haha[p2][0]})) {
for(int i = 0; i < haha[p1].size(); i++) {
ans.push_back(haha[p1][i]);
}
for(int i = 0; i < haha[p2].size(); i++) {
ans.push_back(haha[p2][i]);
}
return ans;
}
if(are_connected({haha[p1][0]},{haha[p2][haha[p2].size()-1]})) {
for(int i = haha[p1].size()-1; i >= 0; i--) {
ans.push_back(haha[p1][i]);
}
for(int i = haha[p2].size()-1; i >= 0; i--) {
ans.push_back(haha[p2][i]);
}
return ans;
}
vector<int> a(0);
vector<int> b(0);
for(int i = 0; i < haha[p1].size(); i++) {
a.push_back(haha[p1][i]);
}
for(int i = 0; i < haha[p2].size(); i++) {
b.push_back(haha[p2][i]);
}
if(!are_connected(a,b)) {
if(a.size() > b.size()) {
return a;
}
else {
return b;
}
}
int x1 = dude(p1,p2,-1);
int x2 = dude(p2,p1,x1);
for(int i = x1+1; i < haha[p1].size(); i++) {
ans.push_back(haha[p1][i]);
}
for(int i = 0; i <= x1; i++) {
ans.push_back(haha[p1][i]);
}
for(int i = x2; i < haha[p2].size(); i++) {
ans.push_back(haha[p2][i]);
}
for(int i = 0; i < x2; i++) {
ans.push_back(haha[p2][i]);
}
return ans;
}
Compilation message
longesttrip.cpp: In function 'void merge(int, int)':
longesttrip.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i = 0; i < haha[b].size(); i++) {
| ~~^~~~~~~~~~~~~~~~
longesttrip.cpp: In function 'int dude(int, int, int)':
longesttrip.cpp:20:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = 0; i < haha[p2].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:88:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i = 0; i < haha[p2].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i = 0; i < haha[p1].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:97:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for(int i = 0; i < haha[p2].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:113:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int i = 0; i < haha[p1].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:116:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for(int i = 0; i < haha[p2].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:129:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for(int i = x1+1; i < haha[p1].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
longesttrip.cpp:135:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int i = x2; i < haha[p2].size(); i++) {
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
600 KB |
Output is correct |
4 |
Correct |
5 ms |
600 KB |
Output is correct |
5 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
600 KB |
Output is correct |
2 |
Correct |
7 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
600 KB |
Output is correct |
4 |
Correct |
6 ms |
600 KB |
Output is correct |
5 |
Correct |
8 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
6 ms |
600 KB |
Output is correct |
8 |
Correct |
6 ms |
600 KB |
Output is correct |
9 |
Correct |
5 ms |
600 KB |
Output is correct |
10 |
Correct |
6 ms |
600 KB |
Output is correct |
11 |
Correct |
8 ms |
600 KB |
Output is correct |
12 |
Correct |
7 ms |
600 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
600 KB |
Output is correct |
2 |
Correct |
5 ms |
628 KB |
Output is correct |
3 |
Correct |
7 ms |
600 KB |
Output is correct |
4 |
Correct |
7 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
600 KB |
Output is correct |
6 |
Correct |
6 ms |
852 KB |
Output is correct |
7 |
Correct |
6 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
600 KB |
Output is correct |
9 |
Correct |
4 ms |
600 KB |
Output is correct |
10 |
Correct |
5 ms |
600 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
9 ms |
600 KB |
Output is correct |
13 |
Correct |
6 ms |
600 KB |
Output is correct |
14 |
Correct |
12 ms |
600 KB |
Output is correct |
15 |
Correct |
14 ms |
600 KB |
Output is correct |
16 |
Correct |
6 ms |
600 KB |
Output is correct |
17 |
Correct |
7 ms |
600 KB |
Output is correct |
18 |
Correct |
5 ms |
780 KB |
Output is correct |
19 |
Correct |
7 ms |
780 KB |
Output is correct |
20 |
Correct |
7 ms |
776 KB |
Output is correct |
21 |
Correct |
8 ms |
600 KB |
Output is correct |
22 |
Correct |
10 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
600 KB |
Output is correct |
24 |
Correct |
9 ms |
776 KB |
Output is correct |
25 |
Correct |
10 ms |
600 KB |
Output is correct |
26 |
Correct |
10 ms |
600 KB |
Output is correct |
27 |
Correct |
9 ms |
600 KB |
Output is correct |
28 |
Correct |
9 ms |
600 KB |
Output is correct |
29 |
Correct |
9 ms |
600 KB |
Output is correct |
30 |
Correct |
8 ms |
600 KB |
Output is correct |
31 |
Correct |
12 ms |
596 KB |
Output is correct |
32 |
Correct |
8 ms |
600 KB |
Output is correct |
33 |
Correct |
7 ms |
600 KB |
Output is correct |
34 |
Correct |
7 ms |
600 KB |
Output is correct |
35 |
Correct |
10 ms |
600 KB |
Output is correct |
36 |
Correct |
9 ms |
600 KB |
Output is correct |
37 |
Correct |
10 ms |
600 KB |
Output is correct |
38 |
Correct |
11 ms |
600 KB |
Output is correct |
39 |
Correct |
9 ms |
600 KB |
Output is correct |
40 |
Correct |
10 ms |
600 KB |
Output is correct |
41 |
Correct |
10 ms |
600 KB |
Output is correct |
42 |
Correct |
12 ms |
600 KB |
Output is correct |
43 |
Correct |
9 ms |
600 KB |
Output is correct |
44 |
Correct |
9 ms |
600 KB |
Output is correct |
45 |
Correct |
7 ms |
600 KB |
Output is correct |
46 |
Correct |
9 ms |
596 KB |
Output is correct |
47 |
Correct |
7 ms |
600 KB |
Output is correct |
48 |
Correct |
6 ms |
600 KB |
Output is correct |
49 |
Correct |
7 ms |
600 KB |
Output is correct |
50 |
Correct |
10 ms |
600 KB |
Output is correct |
51 |
Correct |
13 ms |
600 KB |
Output is correct |
52 |
Correct |
11 ms |
600 KB |
Output is correct |
53 |
Correct |
8 ms |
600 KB |
Output is correct |
54 |
Correct |
10 ms |
600 KB |
Output is correct |
55 |
Correct |
10 ms |
772 KB |
Output is correct |
56 |
Correct |
9 ms |
600 KB |
Output is correct |
57 |
Correct |
12 ms |
776 KB |
Output is correct |
58 |
Correct |
12 ms |
600 KB |
Output is correct |
59 |
Correct |
8 ms |
600 KB |
Output is correct |
60 |
Correct |
11 ms |
780 KB |
Output is correct |
61 |
Correct |
14 ms |
596 KB |
Output is correct |
62 |
Correct |
10 ms |
600 KB |
Output is correct |
63 |
Correct |
9 ms |
600 KB |
Output is correct |
64 |
Correct |
16 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
5 ms |
600 KB |
Output is correct |
3 |
Correct |
5 ms |
600 KB |
Output is correct |
4 |
Correct |
8 ms |
600 KB |
Output is correct |
5 |
Correct |
5 ms |
600 KB |
Output is correct |
6 |
Correct |
11 ms |
600 KB |
Output is correct |
7 |
Correct |
6 ms |
600 KB |
Output is correct |
8 |
Correct |
5 ms |
600 KB |
Output is correct |
9 |
Correct |
6 ms |
600 KB |
Output is correct |
10 |
Correct |
6 ms |
600 KB |
Output is correct |
11 |
Correct |
6 ms |
600 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
14 |
Correct |
16 ms |
600 KB |
Output is correct |
15 |
Correct |
10 ms |
600 KB |
Output is correct |
16 |
Correct |
8 ms |
600 KB |
Output is correct |
17 |
Correct |
6 ms |
600 KB |
Output is correct |
18 |
Correct |
7 ms |
1036 KB |
Output is correct |
19 |
Correct |
6 ms |
776 KB |
Output is correct |
20 |
Correct |
6 ms |
776 KB |
Output is correct |
21 |
Correct |
10 ms |
680 KB |
Output is correct |
22 |
Correct |
11 ms |
600 KB |
Output is correct |
23 |
Correct |
9 ms |
600 KB |
Output is correct |
24 |
Correct |
8 ms |
600 KB |
Output is correct |
25 |
Correct |
9 ms |
600 KB |
Output is correct |
26 |
Correct |
9 ms |
600 KB |
Output is correct |
27 |
Correct |
10 ms |
600 KB |
Output is correct |
28 |
Correct |
12 ms |
600 KB |
Output is correct |
29 |
Correct |
13 ms |
600 KB |
Output is correct |
30 |
Correct |
7 ms |
600 KB |
Output is correct |
31 |
Correct |
9 ms |
600 KB |
Output is correct |
32 |
Correct |
6 ms |
600 KB |
Output is correct |
33 |
Correct |
8 ms |
600 KB |
Output is correct |
34 |
Correct |
10 ms |
600 KB |
Output is correct |
35 |
Correct |
8 ms |
600 KB |
Output is correct |
36 |
Correct |
8 ms |
600 KB |
Output is correct |
37 |
Correct |
6 ms |
600 KB |
Output is correct |
38 |
Correct |
8 ms |
600 KB |
Output is correct |
39 |
Correct |
12 ms |
600 KB |
Output is correct |
40 |
Correct |
7 ms |
600 KB |
Output is correct |
41 |
Correct |
7 ms |
600 KB |
Output is correct |
42 |
Correct |
11 ms |
600 KB |
Output is correct |
43 |
Correct |
6 ms |
600 KB |
Output is correct |
44 |
Correct |
8 ms |
780 KB |
Output is correct |
45 |
Correct |
8 ms |
600 KB |
Output is correct |
46 |
Correct |
6 ms |
776 KB |
Output is correct |
47 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
48 |
Partially correct |
16 ms |
600 KB |
Output is partially correct |
49 |
Partially correct |
12 ms |
600 KB |
Output is partially correct |
50 |
Partially correct |
13 ms |
600 KB |
Output is partially correct |
51 |
Partially correct |
8 ms |
776 KB |
Output is partially correct |
52 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
53 |
Partially correct |
13 ms |
600 KB |
Output is partially correct |
54 |
Partially correct |
12 ms |
600 KB |
Output is partially correct |
55 |
Partially correct |
9 ms |
600 KB |
Output is partially correct |
56 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
57 |
Partially correct |
9 ms |
600 KB |
Output is partially correct |
58 |
Partially correct |
10 ms |
600 KB |
Output is partially correct |
59 |
Partially correct |
10 ms |
856 KB |
Output is partially correct |
60 |
Partially correct |
9 ms |
600 KB |
Output is partially correct |
61 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
62 |
Correct |
8 ms |
600 KB |
Output is correct |
63 |
Partially correct |
14 ms |
600 KB |
Output is partially correct |
64 |
Partially correct |
15 ms |
600 KB |
Output is partially correct |
65 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
66 |
Partially correct |
13 ms |
600 KB |
Output is partially correct |
67 |
Partially correct |
9 ms |
600 KB |
Output is partially correct |
68 |
Partially correct |
14 ms |
600 KB |
Output is partially correct |
69 |
Partially correct |
10 ms |
600 KB |
Output is partially correct |
70 |
Partially correct |
11 ms |
776 KB |
Output is partially correct |
71 |
Partially correct |
14 ms |
784 KB |
Output is partially correct |
72 |
Partially correct |
9 ms |
600 KB |
Output is partially correct |
73 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
74 |
Partially correct |
11 ms |
856 KB |
Output is partially correct |
75 |
Partially correct |
12 ms |
600 KB |
Output is partially correct |
76 |
Partially correct |
10 ms |
600 KB |
Output is partially correct |
77 |
Partially correct |
10 ms |
600 KB |
Output is partially correct |
78 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
79 |
Partially correct |
14 ms |
600 KB |
Output is partially correct |
80 |
Partially correct |
11 ms |
600 KB |
Output is partially correct |
81 |
Partially correct |
14 ms |
600 KB |
Output is partially correct |
82 |
Partially correct |
15 ms |
600 KB |
Output is partially correct |