Submission #840161

# Submission time Handle Problem Language Result Execution time Memory
840161 2023-08-31T07:32:37 Z TranGiaHuy1508 Longest Trip (IOI23_longesttrip) C++17
15 / 100
12 ms 300 KB
#include <bits/stdc++.h>
using namespace std;

#include "longesttrip.h"

namespace {
	vector<int> D3(int N){
		vector<int> res(N);
		iota(res.begin(), res.end(), 0);
		return res;
	}

	vector<int> D2(int N){
		bool edge1 = are_connected({0}, {1});
		bool edge2 = are_connected({1}, {2});
		bool edge3 = are_connected({2}, {0});

		deque<int> res;
		if (edge1 && edge2){
			res.push_back(0); res.push_back(1); res.push_back(2);
		}
		else if (edge2 && edge3){
			res.push_back(1); res.push_back(2); res.push_back(0);
		}
		else{
			res.push_back(2); res.push_back(0); res.push_back(1);
		}

		for (int i = 3; i < N; i++){
			bool e1 = are_connected({i}, {res.front()});

			if (e1) res.push_front(i);
			else res.push_back(i);
		}

		vector<int> vres(res.begin(), res.end());
		return vres;
	}

	vector<int> opt, crr;
	vector<int> vst;
	void find_optimal(int x, vector<vector<int>> &adj){
		crr.push_back(x);
		if (crr.size() > opt.size()) opt = crr;

		vst[x] = 1;

		for (auto k: adj[x]){
			if (vst[k]) continue;
			if (!adj[x][k]) continue;
			find_optimal(k, adj);
		}

		crr.pop_back();
	}
}

vector<int> longest_trip(int N, int D){
	if (D == 3){
		return D3(N);
	}
	if (D == 2){
		return D2(N);
	}

	vector<vector<int>> adj(N, vector<int>(N));
	for (int i = 0; i < N; i++){
		for (int j = i+1; j < N; j++){
			bool edge = are_connected({i}, {j});
			adj[i][j] = adj[j][i] = edge;
		}
	}

	for (int i = 0; i < N; i++){
		vst.assign(N, 0);
		find_optimal(i, adj);
	}

	return opt;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 208 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 208 KB Output is correct
2 Correct 8 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 9 ms 208 KB Output is correct
5 Correct 9 ms 208 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 8 ms 208 KB Output is correct
8 Correct 10 ms 208 KB Output is correct
9 Correct 7 ms 208 KB Output is correct
10 Correct 10 ms 208 KB Output is correct
11 Correct 7 ms 208 KB Output is correct
12 Correct 6 ms 300 KB Output is correct
13 Correct 10 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Incorrect 1 ms 208 KB Incorrect
3 Halted 0 ms 0 KB -