# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1067606 | golf | 가장 긴 여행 (IOI23_longesttrip) | C++17 | 9 ms | 600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
int pop(queue<int> &q) {
int x = q.front();
q.pop();
return x;
}
const bool maybe = true;
vector<int> longest_trip(int N, int D) {
queue<int> nodes;
for (int i = 0; i < N; i++) nodes.push(i);
vector<int> a, b;
a.push_back(pop(nodes));
bool ends_connected = maybe;
// false = a and b are not connected
// true = a and b are maybe connected
while (!nodes.empty()) {
if (b.empty()) {
int n = pop(nodes);
if (are_connected({a.back()}, {n})) {
a.push_back(n);
} else {
// missed optimization
// we could cache that a and b are not connected
b.push_back(n);
ends_connected = false;
}
continue;
}
// both a and b are non-empty
int n = pop(nodes);
if (are_connected({a.back()}, {n})) {
a.push_back(n);
ends_connected = maybe;
} else if (are_connected({b.back()}, {n})) {
b.push_back(n);
ends_connected = false;
} else {
// ends of a and b are definitely connected
for (int i = 0; i < b.size(); i++) {
a.push_back(b.back());
b.pop_back();
}
assert(b.empty());
b.push_back(n);
}
}
if (b.empty()) {
return a;
}
if (ends_connected == maybe && are_connected({a.back()}, {b.back()})) {
for (int i = 0; i < b.size(); i++) {
a.push_back(b.back());
b.pop_back();
}
}
if (!are_connected(a, b)) {
if (a.size() > b.size()) {
return a;
} else {
return b;
}
}
// not finished
if (a.size() > b.size()) {
return a;
} else {
return b;
}
}
컴파일 시 표준 에러 (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... |