#include <bits/stdc++.h>
#include "longesttrip.h"
#warning That's not FB, that's my FB
using namespace std;
vector<int> longest_trip(int N, int D)
{
if (D == 3)
{
vector<int> ans;
for (int i = 0; i < N; i++)
ans.push_back(i);
return ans;
}
if (D == 2)
{
deque<int> chn;
if (are_connected({0}, {1}))
{
chn.push_back(0), chn.push_back(1);
if (are_connected({chn.back()}, {2}))
chn.push_back(2);
else
chn.push_front(2);
}
else
{
chn.push_back(1);
chn.push_back(2);
chn.push_back(0);
}
for (int i = 3; i < N; i++)
{
if (are_connected({i}, {chn.back()}))
chn.push_back(i);
else
chn.push_front(i);
}
vector<int> ans;
while (!chn.empty())
ans.push_back(chn.back()), chn.pop_back();
return ans;
}
vector<int> c1, c2;
c1.push_back(0);
for (int i = 1; i < N; i += 2)
{
if (i + 1 == N)
{
bool b1 = are_connected({i}, {c1.back()});
if (b1)
c1.push_back(i);
else
{
if (c2.empty())
c2.push_back(i);
else
{
bool b2 = are_connected({i}, {c2.back()});
if (b2)
c2.push_back(i);
else
{
while (!c2.empty())
{
c1.push_back(c2.back());
c2.pop_back();
}
c2.push_back(i);
}
}
}
}
else
{
bool bb = are_connected({i}, {i + 1});
if (bb)
{
bool b1 = are_connected({i}, {c1.back()});
if (b1)
c1.push_back(i), c1.push_back(i + 1);
else
{
if (c2.empty())
c2.push_back(i), c2.push_back(i + 1);
else
{
bool b2 = are_connected({i}, {c2.back()});
if (b2)
c2.push_back(i), c2.push_back(i + 1);
else
{
while (!c2.empty())
{
c1.push_back(c2.back());
c2.pop_back();
}
c2.push_back(i), c2.push_back(i + 1);
}
}
}
}
else
{
bool b1 = are_connected({i}, {c1.back()});
if (b1)
{
c1.push_back(i);
if (c2.empty())
c2.push_back(i + 1);
else
{
bool b2 = are_connected({i + 1}, {c2.back()});
if (b2)
c2.push_back(i + 1);
else
{
while (!c2.empty())
{
c1.push_back(c2.back());
c2.pop_back();
}
c2.push_back(i + 1);
}
}
}
else
{
c1.push_back(i + 1);
if (c2.empty())
c2.push_back(i);
else
{
bool b2 = are_connected({i}, {c2.back()});
if (b2)
c2.push_back(i);
else
{
while (!c2.empty())
{
c1.push_back(c2.back());
c2.pop_back();
}
c2.push_back(i);
}
}
}
}
}
}
if (c2.empty())
return c1;
if (!are_connected(c1, c2))
{
if (c1.size() < c2.size())
swap(c1, c2);
return c1;
}
vector<int> tq1, tq2;
tq1.push_back(c1[0]);
if (c1.size() > 1)
tq1.push_back(c1.back());
tq2.push_back(c2[0]);
if (c2.size() > 1)
tq2.push_back(c2.back());
bool bb = are_connected(tq1, tq2);
if (bb)
{
if (are_connected({c1[0]}, {c2[0]}))
{
reverse(c1.begin(), c1.end());
for (auto it : c2)
c1.push_back(it);
return c1;
}
if (are_connected({c1[0]}, {c2.back()}))
{
for (auto it : c1)
c2.push_back(it);
return c2;
}
if (are_connected({c1.back()}, {c2[0]}))
{
for (auto it : c2)
c1.push_back(it);
return c1;
}
reverse(c2.begin(), c2.end());
for (auto it : c2)
c1.push_back(it);
return c1;
}
else
{
int st = -1, pas = 1 << 7;
while (pas != 0)
{
if (st + pas + 1 < c2.size())
{
vector<int> qq;
for (int i = 0; i <= st + pas; i++)
qq.push_back(c2[i]);
bool lmf = are_connected(c1, qq);
if (!lmf)
st += pas;
}
pas /= 2;
}
st++;
int ps2 = st;
int el2 = c2[st];
st = -1, pas = 1 << 7;
while (pas != 0)
{
if (st + pas + 1 < c1.size())
{
vector<int> qq;
for (int i = 0; i <= st + pas; i++)
qq.push_back(c1[i]);
bool lmf = are_connected({el2}, qq);
if (!lmf)
st += pas;
}
pas /= 2;
}
st++;
int ps1 = st;
int el1 = c1[st];
vector<int> ans;
for (int i = ps1 + 1; ; i++)
{
ans.push_back(c1[i % (int)c1.size()]);
if (i % (int)c1.size() == ps1)
break;
}
for (int i = ps2; ; i++)
{
ans.push_back(c2[i % (int)c2.size()]);
if ((i + 1) % (int)c2.size() == ps2)
break;
}
return ans;
}
}
Compilation message
longesttrip.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
3 | #warning That's not FB, that's my FB
| ^~~~~~~
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:199:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
199 | if (st + pas + 1 < c2.size())
| ~~~~~~~~~~~~~^~~~~~~~~~~
longesttrip.cpp:216:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
216 | if (st + pas + 1 < c1.size())
| ~~~~~~~~~~~~~^~~~~~~~~~~
longesttrip.cpp:229:13: warning: unused variable 'el1' [-Wunused-variable]
229 | int el1 = c1[st];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
5 ms |
344 KB |
Output is correct |
6 |
Correct |
5 ms |
344 KB |
Output is correct |
7 |
Correct |
5 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 |
6 ms |
344 KB |
Output is correct |
11 |
Correct |
7 ms |
344 KB |
Output is correct |
12 |
Correct |
6 ms |
344 KB |
Output is correct |
13 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
344 KB |
Output is correct |
2 |
Correct |
6 ms |
344 KB |
Output is correct |
3 |
Correct |
5 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
344 KB |
Output is correct |
5 |
Correct |
5 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 |
6 ms |
344 KB |
Output is correct |
9 |
Correct |
7 ms |
344 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
436 KB |
Output is correct |
12 |
Correct |
4 ms |
340 KB |
Output is correct |
13 |
Correct |
7 ms |
344 KB |
Output is correct |
14 |
Correct |
8 ms |
344 KB |
Output is correct |
15 |
Correct |
7 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
600 KB |
Output is correct |
19 |
Correct |
8 ms |
344 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
344 KB |
Output is correct |
22 |
Correct |
5 ms |
344 KB |
Output is correct |
23 |
Correct |
5 ms |
344 KB |
Output is correct |
24 |
Correct |
4 ms |
344 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
7 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
6 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 |
7 ms |
344 KB |
Output is correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Correct |
6 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
344 KB |
Output is correct |
35 |
Correct |
7 ms |
344 KB |
Output is correct |
36 |
Correct |
5 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
344 KB |
Output is correct |
38 |
Correct |
6 ms |
344 KB |
Output is correct |
39 |
Correct |
7 ms |
344 KB |
Output is correct |
40 |
Correct |
7 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 |
8 ms |
344 KB |
Output is correct |
44 |
Correct |
7 ms |
344 KB |
Output is correct |
45 |
Correct |
9 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
344 KB |
Output is correct |
47 |
Correct |
8 ms |
344 KB |
Output is correct |
48 |
Correct |
11 ms |
344 KB |
Output is correct |
49 |
Correct |
7 ms |
344 KB |
Output is correct |
50 |
Correct |
5 ms |
344 KB |
Output is correct |
51 |
Correct |
10 ms |
344 KB |
Output is correct |
52 |
Correct |
6 ms |
340 KB |
Output is correct |
53 |
Correct |
7 ms |
344 KB |
Output is correct |
54 |
Correct |
6 ms |
344 KB |
Output is correct |
55 |
Correct |
6 ms |
344 KB |
Output is correct |
56 |
Correct |
6 ms |
600 KB |
Output is correct |
57 |
Correct |
6 ms |
448 KB |
Output is correct |
58 |
Correct |
8 ms |
440 KB |
Output is correct |
59 |
Correct |
7 ms |
344 KB |
Output is correct |
60 |
Correct |
6 ms |
452 KB |
Output is correct |
61 |
Correct |
9 ms |
428 KB |
Output is correct |
62 |
Correct |
6 ms |
440 KB |
Output is correct |
63 |
Correct |
6 ms |
344 KB |
Output is correct |
64 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 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 |
5 ms |
344 KB |
Output is correct |
5 |
Correct |
7 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 |
6 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
344 KB |
Output is correct |
10 |
Correct |
5 ms |
344 KB |
Output is correct |
11 |
Correct |
6 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
344 KB |
Output is correct |
13 |
Correct |
7 ms |
344 KB |
Output is correct |
14 |
Correct |
9 ms |
344 KB |
Output is correct |
15 |
Correct |
8 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
344 KB |
Output is correct |
19 |
Correct |
6 ms |
432 KB |
Output is correct |
20 |
Correct |
6 ms |
344 KB |
Output is correct |
21 |
Correct |
5 ms |
344 KB |
Output is correct |
22 |
Correct |
6 ms |
344 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
8 ms |
344 KB |
Output is correct |
25 |
Correct |
6 ms |
344 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
7 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
344 KB |
Output is correct |
29 |
Correct |
5 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
8 ms |
344 KB |
Output is correct |
32 |
Correct |
9 ms |
344 KB |
Output is correct |
33 |
Correct |
11 ms |
344 KB |
Output is correct |
34 |
Correct |
7 ms |
344 KB |
Output is correct |
35 |
Correct |
10 ms |
344 KB |
Output is correct |
36 |
Correct |
7 ms |
344 KB |
Output is correct |
37 |
Correct |
7 ms |
344 KB |
Output is correct |
38 |
Correct |
8 ms |
344 KB |
Output is correct |
39 |
Correct |
10 ms |
344 KB |
Output is correct |
40 |
Correct |
6 ms |
344 KB |
Output is correct |
41 |
Correct |
9 ms |
344 KB |
Output is correct |
42 |
Correct |
9 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 |
9 ms |
592 KB |
Output is correct |
46 |
Correct |
7 ms |
344 KB |
Output is correct |
47 |
Correct |
5 ms |
344 KB |
Output is correct |
48 |
Correct |
6 ms |
344 KB |
Output is correct |
49 |
Correct |
9 ms |
344 KB |
Output is correct |
50 |
Correct |
7 ms |
344 KB |
Output is correct |
51 |
Correct |
7 ms |
344 KB |
Output is correct |
52 |
Correct |
7 ms |
344 KB |
Output is correct |
53 |
Correct |
9 ms |
344 KB |
Output is correct |
54 |
Correct |
7 ms |
344 KB |
Output is correct |
55 |
Correct |
8 ms |
344 KB |
Output is correct |
56 |
Correct |
6 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 |
10 ms |
344 KB |
Output is correct |
61 |
Correct |
6 ms |
344 KB |
Output is correct |
62 |
Correct |
7 ms |
344 KB |
Output is correct |
63 |
Correct |
5 ms |
344 KB |
Output is correct |
64 |
Correct |
9 ms |
440 KB |
Output is correct |
65 |
Correct |
11 ms |
600 KB |
Output is correct |
66 |
Correct |
8 ms |
344 KB |
Output is correct |
67 |
Correct |
7 ms |
428 KB |
Output is correct |
68 |
Correct |
9 ms |
344 KB |
Output is correct |
69 |
Correct |
5 ms |
344 KB |
Output is correct |
70 |
Correct |
8 ms |
440 KB |
Output is correct |
71 |
Correct |
10 ms |
604 KB |
Output is correct |
72 |
Correct |
8 ms |
344 KB |
Output is correct |
73 |
Correct |
8 ms |
344 KB |
Output is correct |
74 |
Correct |
8 ms |
344 KB |
Output is correct |
75 |
Correct |
7 ms |
432 KB |
Output is correct |
76 |
Correct |
8 ms |
440 KB |
Output is correct |
77 |
Correct |
5 ms |
344 KB |
Output is correct |
78 |
Correct |
6 ms |
344 KB |
Output is correct |
79 |
Correct |
7 ms |
600 KB |
Output is correct |
80 |
Correct |
7 ms |
436 KB |
Output is correct |
81 |
Correct |
11 ms |
436 KB |
Output is correct |
82 |
Correct |
12 ms |
436 KB |
Output is correct |