답안 #1056383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056383 2024-08-13T09:08:07 Z jcelin 가장 긴 여행 (IOI23_longesttrip) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "longesttrip.h"
using namespace std;

typedef long long ll;

typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<pll> vpll;

#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define all(x) (x).begin(), (x).end()

const int mod = 1e9 + 7; //998244353;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;
const int logo = 20;
const int MAXN = 1e6 + 7;
const int off = 1 << logo;
const int trsz = off << 1;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};


void nadi(vi &a, vi b){
	int lo = 0, hi = (int)a.size() - 1, ret = -1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		vi vec;
		for(int i=0; i<=mid; i++) vec.PB(a[i]);
		if(are_connected(vec, b)) ret = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	
	int vl = a[ret];
	while(a.back() != vl){
		int x = a.back();
		a.PPB();
		reverse(all(a));
		a.PB(x);
		reverse(all(a));
	}
}

void nadi(vi &a, vi b){
	int lo = 0, hi = (int)a.size() - 1, ret = -1;
	while(lo <= hi){
		int mid = (lo + hi) / 2;
		vi vec;
		for(int i=0; i<=mid; i++) vec.PB(a[i]);
		if(are_connected(vec, b)) ret = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	
	int vl = a[ret];
	while(a.back() != vl){
		int x = a.back();
		a.PPB();
		reverse(all(a));
		a.PB(x);
		reverse(all(a));
	}
}

vi longest_trip(int n, int d){
	vi a = {0}, b = {1};
	
	vi arr;
	for(int i=2; i<n; i++) arr.PB(i);
	shuffle(all(arr), mt19937(time(0)));
	bool nula = 0;
	for(int j=2; j<n; j++){
		int i = arr[j - 2];
		if(are_connected({a.back()}, {i})){
			a.PB(i);
			nula = 0;
			continue;
		}
		
		if(nula or are_connected({b.back()}, {i})){
			b.PB(i);
			nula = 1;
			continue;
		}
		
		while(b.size()) a.PB(b.back()), b.PPB();
		b.PB(i);
	}
	if(a.size() < b.size()) swap(a, b);
	if(!are_connected(a, b)) return a;
	
	if(are_connected({a.front()}, {b.front()})){
		reverse(all(a));
		reverse(all(b));
		while(b.size()) a.PB(b.back()), b.PPB();
		return a;
	}
	
	if(are_connected({a.front()}, {b.back()})){
		reverse(all(a));
		while(b.size()) a.PB(b.back()), b.PPB();
		return a;
	}
	
	if(are_connected({a.back()}, {b.back()})){
		while(b.size()) a.PB(b.back()), b.PPB();
		return a;
	}
	
	
	nadi(b, a);
	nadi(a, {b.back()});
	while(b.size()) a.PB(b.back()), b.PPB();
	return a;
}

Compilation message

longesttrip.cpp:54:6: error: redefinition of 'void nadi(vi&, vi)'
   54 | void nadi(vi &a, vi b){
      |      ^~~~
longesttrip.cpp:34:6: note: 'void nadi(vi&, vi)' previously defined here
   34 | void nadi(vi &a, vi b){
      |      ^~~~