#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
uint64_t randomAddress() {
char *p = new char;
delete p;
return uint64_t(p);
}
uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (randomAddress() | 1);
// mt19937 rng(SEED);
void concat(vector<int> &t1, vector<int> &t2) {
if(t1.size() < t2.size()) {
swap(t1, t2);
}
while(!t2.empty()) {
t1.emplace_back(t2.back());
t2.pop_back();
}
}
std::vector<int> longest_trip(int n, int D) {
srand(SEED);
vector<int> res, ord(n);
iota(ord.begin(), ord.end(), 0);
random_shuffle(ord.begin(), ord.end());
if(D == 3) {
for(const auto &u: ord) {
res.emplace_back(u);
}
} else if(D == 2) {
deque<int> dq;
for(const auto &u: ord) {
if(are_connected({u}, {dq.back()})) {
dq.emplace_back(u);
} else {
dq.emplace_front(u);
}
}
for(const auto &u: dq) {
res.emplace_back(u);
}
} else {
vector<int> t1, t2;
t1.emplace_back(ord.back());
ord.pop_back();
t2.emplace_back(ord.back());
t2.pop_back();
for(const auto &u: ord) {
if(are_connected({u}, {t1.back()})) {
t1.emplace_back(u);
} else if(are_connected({u}, {t2.back()})) {
t2.emplace_back(u);
} else {
concat(t1, t2);
t2.emplace_back(u);
}
}
if(t1.size() < t2.size()) {
swap(t1, t2);
}
for(const auto &u: t1) {
res.emplace_back(u);
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Correct |
6 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 |
6 ms |
344 KB |
Output is correct |
7 |
Incorrect |
5 ms |
344 KB |
non-disjoint arrays |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 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 |
4 ms |
344 KB |
Output is correct |
6 |
Incorrect |
1 ms |
596 KB |
non-disjoint arrays |
7 |
Halted |
0 ms |
0 KB |
- |