이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "longesttrip.h"
#include<random>
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using PP = pair<ll, P>;
const ll n_ = 1e5 + 505, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k;
vector<int> longest_trip(int N,int D){
vector<int>ret;
n=N;
if(D==3){
for(int i=0;i<n;i++)ret.push_back(i);
}
else if(D==2){
vector<int>A={0},B={1},C={2};
deque<ll>T;
if(are_connected(A,B)){
T.push_back(0);
T.push_back(1);
for(int i=2;i<n;i++){
A.clear(),B.clear(),C.clear();
A.push_back(T.front());
C.push_back(i);
if(are_connected(A,C))T.push_front(i);
else T.push_back(i);
}
}
else if(are_connected(B,C)){
T.push_back(1);
T.push_back(2);
for(int i=0;i<n;i++){
if(i==1 || i==2)continue;
A.clear(),B.clear(),C.clear();
A.push_back(T.front());
C.push_back(i);
if(are_connected(A,C))T.push_front(i);
else T.push_back(i);
}
}
else if(are_connected(A,C)){
T.push_back(0);
T.push_back(2);
for(int i=0;i<n;i++){
if(i==0 || i==2)continue;
A.clear(),B.clear(),C.clear();
A.push_back(T.front());
C.push_back(i);
if(are_connected(A,C))T.push_front(i);
else T.push_back(i);
}
}
while(T.size())ret.push_back(T.back()),T.pop_back();
}
else{
vector<vector<ll>>S;
S.push_back({0});
for(int i=1;i<n;i++){
a=S.back().back();
if(are_connected({a},{i}))S.back().push_back(i);
else{
if(S.size()>=2 && S.back().size()==1)S[S.size()-2].push_back(i);
else S.push_back({i});
}
}
if(S.size()==1){
for(auto nxt:S[0])ret.push_back(nxt);
}
else {
vector<ll>A,B;
A=S[0],B=S[1];
for(int i=2;i<n;i++){
vector<ll>T=S[i];
if(are_connected({A.back()},{T[0]})){
for(auto nxt:T)A.push_back(nxt);
}
else if(are_connected({B.back()},{T[0]})){
for(auto nxt:T)B.push_back(nxt);
}
else{
reverse(all(B));
for(auto nxt:B)A.push_back(nxt);
B=T;
}
}
if(A.size()<B.size())swap(A,B);
for(auto i:A)ret.push_back(i);
}
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:64:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
64 | if(are_connected({a},{i}))S.back().push_back(i);
| ^
longesttrip.cpp:64:22: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:78:29: warning: narrowing conversion of 'A.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
78 | if(are_connected({A.back()},{T[0]})){
| ~~~~~~^~
longesttrip.cpp:78:29: warning: narrowing conversion of 'A.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:78:39: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
78 | if(are_connected({A.back()},{T[0]})){
| ^
longesttrip.cpp:78:39: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:81:34: warning: narrowing conversion of 'B.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
81 | else if(are_connected({B.back()},{T[0]})){
| ~~~~~~^~
longesttrip.cpp:81:34: warning: narrowing conversion of 'B.std::vector<long long int>::back()' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
longesttrip.cpp:81:44: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
81 | else if(are_connected({B.back()},{T[0]})){
| ^
longesttrip.cpp:81:44: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
# | 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... |