Submission details
Task:Hamilton
Sender:sofapuden
Submission time:2026-04-17 15:35:18 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
subtaskverdictscore
#10
#20
#30
#40
Test results
testverdicttimescoresubtask
#1--0details
#2--01details
#3--02, 3details
#4--04details

Compiler report

input/code.cpp: In function 'void solve(int)':
input/code.cpp:59:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
   59 |         random_shuffle(perm.begin(), perm.end());
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from input/code.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:4581:5: note: declared here
 4581 |     random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
      |     ^~~~~~~~~~~~~~

Code

#include<bits/stdc++.h>

using namespace std;

vector<string> gr;
int cnt = 0;

vector<int> perm;
vector<vector<int>> mem;

bool que(int u, int v) {
	u = perm[u], v = perm[v];
	if(~mem[u][v]) return mem[u][v];
	cnt++;
	// cout << "? " << u + 1 << ' ' << v + 1 << endl;
	// char c; cin >> c;
	char c = (gr[u][v] == '1' ? '>' : '<');
	mem[u][v] = c == '>';
	mem[v][u] = !mem[u][v];
	return mem[u][v];
}

void ans(vector<int> c) {
	cout << "! ";
	for(auto x : c) cout << x + 1 << ' ';
	cout << endl;
}

void solve4() {
	int n = 4;
	mem.assign(n, vector<int> (n, -1));
	vector<int> c(n);
	iota(c.begin(), c.end(), 0);
	do {
		bool ok = 1;
		for(int i = 0; i < n; ++i) {
			ok &= que(c[i], c[(i + 1) % n]);
		}
		if(ok) {
			ans(c);
			return;
		}
	} while(next_permutation(c.begin(), c.end()));
}

vector<int> merge(vector<int> a, vector<int> b) {
	if(que(a.back(), b[0])) {
		for(auto x : b) a.push_back(x);
		return a;
	}
	else if(que(b.back(), a[0])){
		for(auto x : a) b.push_back(x);
		return b;
	}
	return {-1};
}

void solve(int n) {
	random_shuffle(perm.begin(), perm.end());
	mem.assign(n, vector<int> (n, -1));
	vector<vector<int>> cu;
	for(int i = 0; i < n; ++i) cu.push_back({i});
	for(int i = 0; i + 1 < (int)cu.size(); ++i) {
		auto z = merge(cu[i], cu[i + 1]);
		if(z[0] == -1) continue;
		cu[i] = z;
		cu.erase(cu.begin() + i + 1);
	}
	for(int _ = 0; _ < 2000 && cu.size() > 1; ++_) {
		int a = rand() % (int)cu.size();
		int b = rand() % (int)cu.size();
		if(a == b) continue;
		auto z = merge(cu[a], cu[b]);
		if(z[0] == -1) continue;
		cu[a] = z;
		cu.erase(cu.begin() + b);
	}
	sort(cu.begin(), cu.end(), [&](auto a, auto b) { return a.size() > b.size(); });
	while(cu.size() > 1) {
		for(int i = 0; i < (int)cu[0].size(); ++i) {
			if(que(cu[0][i], cu.back()[0]) && que(cu.back().back(), cu[0][i + 1])) {
				while(cu.back().size()) {
					cu[0].insert(cu[0].begin() + i + 1, cu.back().back());
					cu.back().pop_back();
				}
				break;
			}
		}
		cu.pop_back();
	}
	auto c = cu[0];
	int ls = (int)c.size() - 1;
	while(que(c[0], c[ls])) ls--;
	ls++;
	if(ls < n) {
		for(int i = 0; i < ls; ++i) {
			if(que(c[i], c[ls]) && que(c.back(), c[i + 1])) {
				for(int j = 0; j < (int)c.size() - ls; ++j) {
					c.insert(c.begin() + i + 1, c.back());
					c.pop_back();
				}
				break;
			}
		}
	}
	for(int i = 0; i < n; ++i) assert(que(c[i], c[(i + 1) % n]));
	// ans(c);
}

int sim(int _, int n, int t) {
	srand(_);
	cnt = 0;
	// int n, t; cin >> n >> t;
	perm.resize(n);
	iota(perm.begin(), perm.end(), 0);
	if(n == 4) {
		gr = {"0110", "0011", "0001", "1000"};
		cout << "0110\n0011\n0001\n1000" << endl;
		while(t--) {
			solve4();
		}
		return 0;
	}
	gr.resize(n, string(n, '0'));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			if(i == j) continue;
			int x = rand() & 1;
			gr[i][j] = '1' - x;
			gr[j][i] = '0' + x;
		}
	}
	// for(auto x : gr) cout << x << endl;
	while(t--) solve(n);
	return cnt;
}

int main() {
	pair<int, int> bes = {1 << 30, -1};
	for(int i = 0; i < 2000; ++i) {
		pair<int, int> cu = make_pair(sim(i, 500, 200), i);	
		bes = min(bes, cu);
		if(i % 100 == 0) {
			cerr << bes.first << ' ' << bes.second << '\n';
		}
	}
	cout << bes.first << ' ' << bes.second << '\n';
}

Test details

Test 1

Subtask:

Verdict:

input
0 5 2 fixed 1 2 3 4 5 2 4 1 5 ...

correct output
(empty)

user output
(empty)

Test 2

Subtask: 1

Verdict:

input
01 4 200 rnd

correct output
(empty)

user output
(empty)

Test 3

Subtask: 2, 3

Verdict:

input
02 50 200 rnd

correct output
(empty)

user output
(empty)

Test 4

Subtask: 4

Verdict:

input
03 500 200 rnd

correct output
(empty)

user output
(empty)