Submission details
Task:Hamilton
Sender:frederikvase
Submission time:2026-04-17 14:55:47 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
subtaskverdictscore
#10
#20
#30
#40
Test results
testverdicttimescoresubtask
#10.01 s0details
#20.01 s01details
#30.01 s02, 3details
#40.48 s04details

Compiler report

input/code.cpp: In function 'void solve(int)':
input/code.cpp:55:14: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
   55 |         bool ok = false;
      |              ^~

Code

#include <bits/stdc++.h>
using namespace std;

mt19937 mt;

bool query(int u, int v) { // is from u to v
	cout << "? " << u + 1 << " " << v + 1 << endl;
	char c;
	cin >> c;
	return c == '>';
}

int checksum(vector<vector<int>> &v) {
	int sum = 0;
	for (auto &e : v) {
		sum += int(e.size());
	}
	return sum;
}

void solve(int n) {
	vector<vector<int>> chain;
	for (int i = 0; i < n; i += 2) {
		if (query(i, i + 1)) chain.push_back({i, i + 1});
		else chain.push_back({i + 1, i});
	}
	//assert(checksum(chain) == n);

	const int mnsize = 40;
	vector<vector<int>> good;
	while (chain.size() > 6) {
		int i = mt() % int(chain.size());
		int j = mt() % int(chain.size());
		if (i == j) continue;
		if (int(chain[j].size()) >= mnsize) {
			good.push_back(chain[j]);
			chain.erase(chain.begin() + j);
			continue;
		}
		if (int(chain[i].size()) >= mnsize) {
			good.push_back(chain[i]);
			chain.erase(chain.begin() + i);
			continue;
		}

		if (query(chain[i].back(), chain[j].front())) {
			for (int e : chain[j]) chain[i].push_back(e);
			chain.erase(chain.begin() + j);
		}
	}
	//assert(checksum(chain) + checksum(good) == n);

	swap(good, chain);

	bool ok = false;
	for (int i = 0; i < int(chain.size()); i++) {
		//assert(int(chain[i].size()) >= mnsize);

		if (query(chain[i].back(), chain[i].front())) {
			ok = true;
			swap(chain[0], chain[i]);
		}
	}
	//assert(ok);

	for (auto v : good) chain.push_back(v);

	int sum = int(chain[0].size());
	for (int i = 1; i < int(chain.size()); i++) {
		sum += int(chain[i].size());
		while (true) {
			int j = mt() % (int(chain[0].size()) - 1);
			if (query(chain[0][j], chain[i].front()) && query(chain[i].back(), chain[0][j + 1])) {
				chain[0].insert(next(chain[0].begin(), j + 1), chain[i].begin(), chain[i].end());
				break;
			}
		}
	}

	//assert(sum >= n);
	//assert(int(chain[0].size()) == n);
	
	cout << "!";
	for (int e : chain[0]) {
		cout << " " << e + 1;
	}
	cout << endl;
}

signed main() {
	int n, t;
	cin >> n >> t;

	random_device rd;
	mt.seed(rd());

	vector<vector<int>> g(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int x = mt() % 2;
			g[i][j] = x;
			g[j][i] = x ^ 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << g[i][j];
		}
		cout << "\n";
	}

	while (t--) {
		solve(n);
	}

	return 0;
}

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
Activating encoder mode
5 2
00000
10100
10000
...

Feedback: Case #1: Invalid query

Test 2

Subtask: 1

Verdict:

input
01 4 200 rnd

correct output
(empty)

user output
Activating encoder mode
4 200
0010
1001
0101
...

Feedback: Case #1: Wrong edge in answer, 1 to 2

Test 3

Subtask: 2, 3

Verdict:

input
02 50 200 rnd

correct output
(empty)

user output
Activating encoder mode
50 200
001101101110111011011101010100...

Feedback: Case #1: Wrong edge in answer, 30 to 3

Test 4

Subtask: 4

Verdict:

input
03 500 200 rnd

correct output
(empty)

user output
Activating encoder mode
500 200
001111100100000001011100000011...

Feedback: Case #19: Wrong edge in answer, 268 to 72