Submission details
Task:Hamilton
Sender:frederikvase
Submission time:2026-04-17 14:34:27 +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
#43.30 s04details

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 == '>';
}

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});
	}

	while (int(chain.size()) > 20) {
		int i = mt() % int(chain.size());
		int j = mt() % int(chain.size());
		if (i == j) continue;

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

	bool ok = false;
	for (int i = 0; i < int(chain.size()); i++) if (int(chain[i].size()) > 10) {
		if (query(chain[i].back(), chain[i].front())) {
			ok = true;
			swap(chain[0], chain[i]);
		}
	}
	assert(ok);

	for (int i = 1; i < int(chain.size()); i++) {
		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;
			}
		}
	}
	
	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
01111
00110
00001
...

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
0001
1000
1101
...

Test 3

Subtask: 2, 3

Verdict:

input
02 50 200 rnd

correct output
(empty)

user output
Activating encoder mode
50 200
010001100010001110111101010100...

Test 4

Subtask: 4

Verdict:

input
03 500 200 rnd

correct output
(empty)

user output
Activating encoder mode
500 200
010001011111110111110111111101...

Feedback: Case #129: Too many queries