답안 #841593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
841593 2023-09-01T18:09:58 Z andrei_c1 가장 긴 여행 (IOI23_longesttrip) C++17
5 / 100
7 ms 600 KB
#include "longesttrip.h"
#include <bits/stdc++.h>

using namespace std;

uint64_t randomAddress() {
	char *p = new char;
	delete p;
	return uint64_t(p);
}
uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (randomAddress() | 1);
// mt19937 rng(SEED);

void concat(vector<int> &t1, vector<int> &t2) {
	if(t1.size() < t2.size()) {
		swap(t1, t2);
	}
	while(!t2.empty()) {
		t1.emplace_back(t2.back());
		t2.pop_back();
	}
}

std::vector<int> longest_trip(int n, int D) {
	srand(SEED);
	vector<int> res, ord(n);
	iota(ord.begin(), ord.end(), 0);
	random_shuffle(ord.begin(), ord.end());
	if(D == 3) {
		for(const auto &u: ord) {
			res.emplace_back(u);
		}
	} else if(D == 2) {
		deque<int> dq;
		dq.emplace_back(ord.back());
		ord.pop_back();
		for(const auto &u: ord) {
			if(are_connected({u}, {dq.back()})) {
				dq.emplace_back(u);
			} else {
				dq.emplace_front(u);
			}
		}
		for(const auto &u: dq) {
			res.emplace_back(u);
		}
	} else {
		vector<int> t1, t2;
		t1.emplace_back(ord.back());
		ord.pop_back();
		t2.emplace_back(ord.back());
		t2.pop_back();
		for(const auto &u: ord) {
			if(are_connected({u}, {t1.back()})) {
				t1.emplace_back(u);
			} else if(are_connected({u}, {t2.back()})) {
				t2.emplace_back(u);
			} else {
				concat(t1, t2);
				t2.emplace_back(u);
			}
		}
		if(t1.size() < t2.size()) {
			swap(t1, t2);
		}
		for(const auto &u: t1) {
			res.emplace_back(u);
		}
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 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 600 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 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 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB non-disjoint arrays
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 432 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 -