이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;
std::vector<int> longest_trip(int N, int D)
{
vector<int> path{0};
vector<int> rest(N-1);
iota(rest.begin(),rest.end(),1);
while (rest.size()) {
bool can = are_connected(path,rest);
if (!can) {
if (path.size() >= rest.size()) return path;
return rest;
}
int lo = 0, hi = rest.size();
while (hi-lo > 1) {
int mid = (lo+hi)/2;
vector<int> cand;
for (auto it = rest.begin()+lo; it != rest.begin()+mid; ++it) {
cand.push_back(*it);
}
bool res = are_connected(path,cand);
if (res) {
hi = mid;
} else {
lo = mid;
}
}
int nxt = rest[lo];
rest.erase(rest.begin()+lo);
if (are_connected({path.back()},{nxt})) {
path.push_back(nxt);
} else {
lo = 0; hi = path.size();
while (hi-lo > 1) {
int mid = (lo+hi)/2;
vector<int> cand;
for (auto it = path.begin()+lo; it != path.begin()+mid; ++it) {
cand.push_back(*it);
}
bool res = are_connected(cand,{nxt});
if (res) {
hi = mid;
} else {
lo = mid;
}
}
if (lo == 0) {
path.insert(path.begin(),nxt);
} else {
rotate(path.begin(),path.begin()+lo+1,path.end());
path.push_back(nxt);
}
}
}
return path;
}
| # | 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... |