// correct/solution-subtask2.cpp
#include "longesttrip.h"
#include <algorithm>
#include <random>
#include <deque>
std::vector<int> longest_trip(int N, int /*D*/)
{
srand(time(0));
std::vector<int> ids(N);
for (int i = 0; i < N; i++)
ids[i] = i;
random_shuffle(ids.begin(), ids.end());
std::deque<int> line;
line.clear();
if (!are_connected({ids[0]}, {ids[1]}))
{
std::swap(ids[0], ids[2]);
}
line.push_back(ids[0]);
line.push_back(ids[1]);
for (int i = 2; i < N; i++)
{
if (are_connected({ids[i]}, {line.back()}))
{
line.push_back(ids[i]);
}
else if (are_connected({ids[i]}, {line.front()}))
{
line.push_front(ids[i]);
}
else
{
break;
}
}
std::vector<int> ans;
ans.clear();
for (int i : line)
ans.push_back(i);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
208 KB |
Output is correct |
2 |
Correct |
6 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
7 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
12 ms |
336 KB |
Output is correct |
5 |
Correct |
7 ms |
208 KB |
Output is correct |
6 |
Correct |
9 ms |
208 KB |
Output is correct |
7 |
Correct |
8 ms |
208 KB |
Output is correct |
8 |
Correct |
7 ms |
208 KB |
Output is correct |
9 |
Correct |
4 ms |
208 KB |
Output is correct |
10 |
Correct |
8 ms |
208 KB |
Output is correct |
11 |
Correct |
5 ms |
284 KB |
Output is correct |
12 |
Correct |
10 ms |
288 KB |
Output is correct |
13 |
Correct |
9 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
208 KB |
Output is correct |
2 |
Correct |
11 ms |
208 KB |
Output is correct |
3 |
Correct |
6 ms |
208 KB |
Output is correct |
4 |
Correct |
6 ms |
208 KB |
Output is correct |
5 |
Correct |
6 ms |
208 KB |
Output is correct |
6 |
Correct |
10 ms |
208 KB |
Output is correct |
7 |
Correct |
11 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
9 |
Correct |
13 ms |
208 KB |
Output is correct |
10 |
Correct |
9 ms |
208 KB |
Output is correct |
11 |
Correct |
10 ms |
256 KB |
Output is correct |
12 |
Correct |
10 ms |
288 KB |
Output is correct |
13 |
Correct |
9 ms |
208 KB |
Output is correct |
14 |
Incorrect |
0 ms |
208 KB |
Incorrect |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
6 ms |
208 KB |
Output is correct |
3 |
Correct |
13 ms |
208 KB |
Output is correct |
4 |
Correct |
8 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
7 ms |
208 KB |
Output is correct |
8 |
Correct |
6 ms |
208 KB |
Output is correct |
9 |
Correct |
9 ms |
208 KB |
Output is correct |
10 |
Correct |
6 ms |
208 KB |
Output is correct |
11 |
Correct |
6 ms |
208 KB |
Output is correct |
12 |
Correct |
8 ms |
208 KB |
Output is correct |
13 |
Correct |
4 ms |
208 KB |
Output is correct |
14 |
Incorrect |
0 ms |
208 KB |
Incorrect |
15 |
Halted |
0 ms |
0 KB |
- |