이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
int i, j, k, a, b, A[260][260], B[260];
vector<int> longest_trip(int N, int D)
{
vector<int>v1, v2;
v1.push_back(0);
v2.push_back(1);
bool flag=false;
for(i=2;i<N;i++)
{
vector<int>X, Y, Z;
X.push_back(v1.back());Y.push_back(i);Z.push_back(v2.back());
if(are_connected(X, Y))v1.push_back(i);
else if(are_connected(Z, Y))v2.push_back(i);
else
{
while(v2.size())
{
v1.push_back(v2.back());
v2.pop_back();
}
v2.push_back(i);
}
}
if(are_connected(v1, v2)==0)
{
if(v1.size()<v2.size())swap(v1, v2);
return v1;
}
vector<int>X, Y, Z, W;
X.push_back(v1.back());
Z.push_back(v2[0]);W.push_back(v2.back());
if(are_connected(X, Z))
{
for(auto p:v2)v1.push_back(p);
return v1;
}
if(are_connected(X, W))
{
while(v2.size())
{
v1.push_back(v2.back());
v2.pop_back();
}
return v1;
}
if(are_connected(X, v2))
{
int s=0, e=v2.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(X, V))e=m;
else s=m+1;
}
for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
for(i=0;i<s;i++)v1.push_back(v2[i]);
return v1;
}
Y.push_back(v1[0]);
if(are_connected(Y, v2))
{
int s=0, e=v2.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(Y, V))e=m;
else s=m+1;
}
reverse(v1.begin(), v1.end());
for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
for(i=0;i<s;i++)v1.push_back(v2[i]);
return v1;
}
int s=0, e=v1.size()-1;
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v1[i]);
if(are_connected(V, v2))e=m;
else s=m+1;
}
int ss=s;
s=0, e=v2.size()-1;
X[0]=v1[s];
while(s<e)
{
int m=s+e>>1;
vector<int>V;
for(i=0;i<=m;i++)V.push_back(v2[i]);
if(are_connected(X, V))e=m;
else s=m+1;
}
vector<int>ans;
for(i=ss-1;i>=0;i--)ans.push_back(v1[i]);
for(i=v1.size()-1;i>=ss;i--)ans.push_back(v1[i]);
for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
for(i=0;i<s;i++)ans.push_back(v2[i]);
return v2;
}
컴파일 시 표준 에러 (stderr) 메시지
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:55:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int m=s+e>>1;
| ~^~
longesttrip.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:71:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int m=s+e>>1;
| ~^~
longesttrip.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(i=s;i<v2.size();i++)v1.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:85:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
85 | int m=s+e>>1;
| ~^~
longesttrip.cpp:96:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | int m=s+e>>1;
| ~^~
longesttrip.cpp:105:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for(i=s;i<v2.size();i++)ans.push_back(v2[i]);
| ~^~~~~~~~~~
longesttrip.cpp:11:10: warning: unused variable 'flag' [-Wunused-variable]
11 | bool flag=false;
| ^~~~
# | 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... |