답안 #1064100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064100 2024-08-18T09:13:35 Z DorostWef 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
9 ms 436 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

#define ask are_connected

std::vector<int> longest_trip(int N, int D) {
	int n = N;
	vector <int> A = {0}, B;
	for (int i = 1; i < n; i++) {
		if (B.empty()) {
			bool f = ask ({A.back()}, {i});
			if (f)
				A.push_back(i);
			else {
				B.push_back(i);
			}
		} else {
			if (ask ({A.back()}, {B[0]})) {
				for (int x : B)
					A.push_back(x);
				B.clear();
				i--;
			} else if (ask ({A.back()}, {i})) {
				A.push_back(i);
			} else {
				B.push_back(i);
			}
		}
	}/*
		cout << "A : ";
		for (int x : A)
		cout << x << ' ';
		cout << '\n';
		cout << "B : ";
		for (int y : B)
		cout << y << ' ';
		cout << '\n';*/
	if (B.empty())
		return A;
	if (!ask (A, B)) {
		if (A.size() >= B.size())
			return A;
		return B;
	}
	if (ask ({A[0]}, {B[0]})) {
		reverse (A.begin(), A.end());
		for (int x : B) {
			A.push_back(x);
		}
		return A;
	} else {
		bool f;
		if (A.size() >= 2) {
			f = ask ({A[0]}, {A.back()});
			if (!f) {
				for (int x : B) {
					A.push_back(x);
				}
				return A;
			}
		} 
		if (B.size() >= 2) {
			f = ask ({B[0]}, {B.back()});
			if (!f) {
				for (int x : A) {
					B.push_back(x);
				}
				return B;
			}
		}
	}
	return B;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 9 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 6 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Incorrect 1 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -