이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng(15645869);
std::vector<int> longest_trip(int N, int D)
{
vector<int>x, y;
vector<int>p;
for(int i=0;i<N;i++){
p.push_back(i);
}
shuffle(p.begin(),p.end(),rng);
int color[N];
for(int i=0;i<N;i++){
color[i]=0;
}
for(int i:p){
if(x.size()==0){
x={i};
color[i]=1;
continue;
}
if(y.size()==0){
if(are_connected({i}, {x[0]})){
x.insert(x.begin(),i);
continue;
}
if (are_connected({i}, {x.back()})){
x.push_back(i);
continue;
}
if(!are_connected({i}, x)){
y={i};
for(int i: x){
color[i]=1;
}
for(int i: y){
color[i]=2;
}
continue;
}
int lo=1;
int hi=x.size()-2;
int c=color[x[0]];
if(c==0){
c=color[x.back()];
}
if(c!=0){
color[i]=3-c;
}
for(int i=lo;i<=hi;i++){
if(color[x[i]]!=c && color[x[i]]!=0 && c!=0){
lo=hi=i;
}
}
while(lo<hi){
int m=(lo+hi)/2;
vector<int>z;
for(int i=lo;i<=m;i++){
z.push_back(x[i]);
}
if(are_connected(z, {i})){
hi=m;
} else{
lo=m+1;
}
}
vector<int>z;
for(int i=lo+1;i<x.size();i++){
z.push_back(x[i]);
}
for(int i=0;i<=lo;i++){
z.push_back(x[i]);
}
z.push_back(i);
x=z;
continue;
}
if(!are_connected(x,{i})){
y.push_back(i);
color[i]=color[y[0]];
continue;
}
if(!are_connected(y,{i})){
x.push_back(i);
color[i]=color[x[0]];
continue;
}
int i0=0;
int j0=0;
if(!are_connected({x[0]},{i})){
int lo=1;
int hi=x.size()-1;
while(lo<hi){
int m=(lo+hi)/2;
vector<int>z;
for(int i=lo;i<=m;i++){
z.push_back(x[i]);
}
if(are_connected(z, {i})){
hi=m;
} else{
lo=m+1;
}
}
i0=lo;
} else {
int lo=0;
int hi=y.size()-1;
while(lo<hi){
int m=(lo+hi)/2;
vector<int>z;
for(int i=lo;i<=m;i++){
z.push_back(y[i]);
}
if(are_connected(z, {i})){
hi=m;
} else{
lo=m+1;
}
}
j0=lo;
}
swap(x[i0], x.back());
swap(y[j0], y[0]);
x.push_back(i);
for(int i: y){
x.push_back(i);
}
y={};
}
if(x.size()>y.size()){
return x;
} else{
return y;
}
}
컴파일 시 표준 에러 (stderr) 메시지
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:70:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i=lo+1;i<x.size();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... |