#include "longesttrip.h"
#define pb push_back
using namespace std;
// Find the first posiion i such that v[i] is connected to i
int find_position(vector<int>& v, int i)
{
int l = 0;
int r = v.size();
while (l + 1 < r) {
int mid = (l + r) / 2;
if (are_connected(vector<int>(v.begin(), v.begin() + mid), {i})) {
r = mid;
}
else {
l = mid;
}
}
return l;
}
vector<int> longest_trip(int N, int D)
{
vector<int> v1, v2;
v1.push_back(0);
for (int i = 1; i < N; i++) {
if (are_connected(v1, {i})) {
if (v2.size()) {
if (are_connected(v2, {i})) {
int p1 = find_position(v1, i);
int p2 = find_position(v2, i);
v1.insert(v1.begin(), v1.begin() + p1 + 1, v1.end());
v1.erase(v1.begin() + p1 + 1, v1.end());
v1.pb(i);
v1.insert(v1.end(), v2.begin() + p2, v2.end());
v1.insert(v1.end(), v2.begin(), v2.begin() + p2);
v2.clear();
}
else {
v1.pb(i);
}
}
else {
if (are_connected({v1.back()}, {i})) {
v1.pb(i);
}
else {
int p = find_position(v1, i);
v1.insert(v1.end(), v1.begin(), v1.begin() + p);
v1.erase(v1.begin(), v1.begin() + p);
v1.insert(v1.begin(), i);
}
}
}
else {
v2.pb(i);
}
}
if (v1.size() > v2.size()) {
return v1;
}
else {
return v2;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
11 ms |
344 KB |
Output is correct |
5 |
Correct |
17 ms |
696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
344 KB |
Output is correct |
2 |
Correct |
7 ms |
344 KB |
Output is correct |
3 |
Correct |
11 ms |
344 KB |
Output is correct |
4 |
Correct |
15 ms |
344 KB |
Output is correct |
5 |
Correct |
23 ms |
344 KB |
Output is correct |
6 |
Correct |
8 ms |
344 KB |
Output is correct |
7 |
Correct |
11 ms |
344 KB |
Output is correct |
8 |
Correct |
11 ms |
344 KB |
Output is correct |
9 |
Correct |
14 ms |
344 KB |
Output is correct |
10 |
Correct |
14 ms |
344 KB |
Output is correct |
11 |
Correct |
16 ms |
344 KB |
Output is correct |
12 |
Correct |
14 ms |
344 KB |
Output is correct |
13 |
Correct |
15 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
344 KB |
Output is correct |
2 |
Correct |
10 ms |
344 KB |
Output is correct |
3 |
Correct |
13 ms |
344 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
15 ms |
344 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
344 KB |
Output is correct |
8 |
Correct |
15 ms |
344 KB |
Output is correct |
9 |
Correct |
16 ms |
344 KB |
Output is correct |
10 |
Correct |
14 ms |
600 KB |
Output is correct |
11 |
Correct |
20 ms |
344 KB |
Output is correct |
12 |
Correct |
20 ms |
344 KB |
Output is correct |
13 |
Correct |
22 ms |
600 KB |
Output is correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Incorrect |
1 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
344 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
12 ms |
344 KB |
Output is correct |
5 |
Partially correct |
23 ms |
432 KB |
Output is partially correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Correct |
8 ms |
344 KB |
Output is correct |
8 |
Correct |
11 ms |
344 KB |
Output is correct |
9 |
Correct |
12 ms |
344 KB |
Output is correct |
10 |
Partially correct |
15 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
14 ms |
344 KB |
Output is partially correct |
12 |
Partially correct |
15 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
15 ms |
344 KB |
Output is partially correct |
14 |
Correct |
6 ms |
344 KB |
Output is correct |
15 |
Incorrect |
2 ms |
344 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |