이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=305;
std::vector<int> longest_trip(int N, int D)
{
vector<int> d[2];
d[0].push_back(0);
d[1].push_back(1);
bool not_connected=0;
for (int i=2; i<N; i++)
{
if (are_connected(vector<int> {d[0].back()}, vector<int> {i}))
{
not_connected=0;
d[0].push_back(i);
continue;
}
if (not_connected||are_connected(vector<int> {d[1].back()}, vector<int> {i}))
{
not_connected=1;
d[1].push_back(i);
continue;
}
if (d[1].size()==1) not_connected=1;
else not_connected=0;
while (!d[1].empty()) d[0].push_back(d[1].back()), d[1].pop_back();
d[1].push_back(i);
}
if (!are_connected(d[0], d[1])) return d[0].size()>d[1].size()?d[0]:d[1];
if (are_connected(vector<int> {d[0].front()}, vector<int> {d[1].front()}))
{
reverse(d[0].begin(), d[0].end());
for (auto x:d[1]) d[0].push_back(x);
return d[0];
}
if (are_connected(vector<int> {d[0].front()}, vector<int> {d[1].back()}))
{
for (auto x:d[0]) d[1].push_back(x);
return d[1];
}
if (are_connected(vector<int> {d[0].back()}, vector<int> {d[1].front()}))
{
for (auto x:d[1]) d[0].push_back(x);
return d[0];
}
if (are_connected(vector<int> {d[0].back()}, vector<int> {d[1].back()}))
{
reverse(d[1].begin(), d[1].end());
for (auto x:d[1]) d[0].push_back(x);
return d[0];
}
int l=0, r=d[0].size()-1;
while (l<r)
{
int md=(l+r)/2;
vector<int> a;
for (int i=0; i<=md; i++) a.push_back(d[0][i]);
if (are_connected(a, d[1])) r=md;
else l=md+1;
}
int x=l;
l=0, r=d[1].size()-1;
while (l<r)
{
int md=(l+r)/2;
vector<int> a;
for (int i=0; i<=md; i++) a.push_back(d[1][i]);
if (are_connected(a, vector<int> {d[0][x]})) r=md;
else l=md+1;
}
vector<int> res;
for (int i=x+1; i<d[0].size(); i++) res.push_back(d[0][i]);
for (int i=0; i<=x; i++) res.push_back(d[0][i]);
for (int i=l; i<d[1].size(); i++) res.push_back(d[1][i]);
for (int i=0; i<l; i++) res.push_back(d[1][i]);
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int i=x+1; i<d[0].size(); i++) res.push_back(d[0][i]);
| ~^~~~~~~~~~~~
longesttrip.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i=l; i<d[1].size(); i++) res.push_back(d[1][i]);
| ~^~~~~~~~~~~~
# | 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... |