이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
vector<int> longest_trip(int N, int D) {
int n = N;
auto ask = [&](int x, int y) -> bool {
return are_connected(vector<int>{x}, vector<int>{y});
};
vector<int> a{0}, b;
for (int i = 1; i < n; ++i) {
if (ask(a.back(), i)) {
a.push_back(i);
} else {
b.push_back(i);
}
if (b.size() && ask(b.back(), a.back())) {
reverse(b.begin(), b.end());
for (auto j : b) {
a.push_back(j);
}
b.clear();
}
}
if (b.size() && are_connected(a, b)) {
if (are_connected(vector<int>{a.back()}, vector<int>(b.begin(), b.end())) == 0) {
int l = 1, r = b.size();
while (l <= r) {
int mid = (l + r) / 2;
if (are_connected(a, vector<int>(b.begin(), b.begin() + mid))) {
r = mid - 1;
} else {
l = mid + 1;
}
}
++r;
swap(b[r - 1], b.back());
swap(a, b);
}
if (ask(a.back(), b.back())) {
reverse(b.begin(), b.end());
}
while (ask(a.back(), b[0]) == 0) {
b.push_back(b[0]);
b.erase(b.begin());
}
for (auto j : b) {
a.push_back(j);
}
b.clear();
} else {
if (a.size() < b.size()) {
swap(a, b);
}
}
return a;
}
# | 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... |