#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
// Subtask 1: D == 3
vector<int> sub1(int n) {
vector<int> res(n);
std::iota(res.begin(), res.end(), 0);
return res;
}
// Subtask 2: D == 2
vector<int> sub2(int n) {
vector<int> res {0};
for (int i = 1; i < n; i++) {
if (are_connected({0}, {i})) {
res.push_back(i);
break;
}
}
for (int i = 1; i < n; i++) {
if (i == res[1]) continue;
if (are_connected({res.back()}, {i})) {
res.push_back(i);
} else {
res.insert(res.begin(), i);
}
}
return res;
}
// Subtask 3: D == 1, return path with length >= Lmax / 2
mt19937_64 rng(58);
vector<int> sub3(int n) {
vector<int> ids(n);
std::iota(ids.begin(), ids.end(), 0);
std::shuffle(ids.begin(), ids.end(), rng);
vector<int> res {ids[0]};
for (int i = 1; i < n; i++) {
if (are_connected({ids[0]}, {ids[i]})) {
res.push_back(ids[i]);
break;
}
}
for (int i = 1; i < n; i++) {
if (ids[i] == res[1]) continue;
for (int turn = 0; turn < i - 1; ++turn) {
if (are_connected({res.back()}, {ids[i]})) {
res.push_back(ids[i]);
break;
} else if (are_connected({res[0]}, {ids[i]})) {
res.insert(res.begin(), ids[i]);
break;
} else {
int u = res.back();
res.pop_back();
res.insert(res.begin(), u);
}
}
}
return res;
}
vector<int> longest_trip(int n, int d) {
if (d == 3) return sub1(n);
if (d == 2) return sub2(n);
return sub3(n);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
208 KB |
Output is correct |
2 |
Correct |
2 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
10 ms |
208 KB |
Output is correct |
3 |
Correct |
5 ms |
208 KB |
Output is correct |
4 |
Correct |
7 ms |
208 KB |
Output is correct |
5 |
Correct |
10 ms |
208 KB |
Output is correct |
6 |
Correct |
10 ms |
208 KB |
Output is correct |
7 |
Correct |
9 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
208 KB |
Output is correct |
10 |
Correct |
10 ms |
208 KB |
Output is correct |
11 |
Correct |
9 ms |
336 KB |
Output is correct |
12 |
Correct |
9 ms |
208 KB |
Output is correct |
13 |
Correct |
8 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
208 KB |
Output is correct |
2 |
Correct |
8 ms |
208 KB |
Output is correct |
3 |
Correct |
8 ms |
208 KB |
Output is correct |
4 |
Correct |
11 ms |
208 KB |
Output is correct |
5 |
Correct |
9 ms |
208 KB |
Output is correct |
6 |
Correct |
8 ms |
208 KB |
Output is correct |
7 |
Correct |
8 ms |
208 KB |
Output is correct |
8 |
Correct |
9 ms |
208 KB |
Output is correct |
9 |
Correct |
8 ms |
208 KB |
Output is correct |
10 |
Correct |
7 ms |
208 KB |
Output is correct |
11 |
Correct |
10 ms |
240 KB |
Output is correct |
12 |
Correct |
10 ms |
208 KB |
Output is correct |
13 |
Correct |
10 ms |
208 KB |
Output is correct |
14 |
Correct |
10 ms |
208 KB |
Output is correct |
15 |
Incorrect |
0 ms |
208 KB |
Incorrect |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
208 KB |
Output is correct |
2 |
Correct |
9 ms |
208 KB |
Output is correct |
3 |
Correct |
9 ms |
208 KB |
Output is correct |
4 |
Correct |
9 ms |
208 KB |
Output is correct |
5 |
Correct |
8 ms |
208 KB |
Output is correct |
6 |
Incorrect |
0 ms |
208 KB |
Incorrect |
7 |
Halted |
0 ms |
0 KB |
- |