# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080591 | shmax | Longest Trip (IOI23_longesttrip) | C++17 | 9 ms | 600 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "longesttrip.h"
#include "bits/stdc++.h"
using namespace std;
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define inf 1000'000'000'000'000'000LL
#define bit(x, i) (((x) >> i) & 1)
template<typename T>
using vec = vector<T>;
std::vector<int> longest_trip(int n, int d) {
mt19937 rnd(14345);
if (d == 3) {
vec<int> ans(n);
iota(all(ans), 0);
return ans;
}
if (d == 2) {
deque<int> ans;
int cur = 0;
ans.push_back(cur);
set<int> not_used;
for (int i = 1; i < n; i++) {
not_used.insert(i);
}
while (true) {
if(not_used.empty()) break;
vec<int> next(all(not_used));
int nxt = next[rnd() % len(next)];
if (are_connected({cur}, {nxt})) {
ans.push_back(nxt);
not_used.erase(nxt);
cur = nxt;
} else {
if (next.size() == 1) {
ans.push_front(next[0]);
break;
} else {
int net = next[rnd() % len(next)];
while (net == nxt) {
net = next[rnd() % len(next)];
}
ans.push_back(net);
not_used.erase(net);
}
}
}
return vec<int>(all(ans));
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |