Submission details
Task:Hamilton
Sender:Asarbardjarn
Submission time:2026-04-17 12:01:11 +0300
Language:C++ (C++23)
Status:READY
Result:90
Feedback
subtaskverdictscore
#1ACCEPTED5
#2ACCEPTED7
#3ACCEPTED12
#4ACCEPTED66
Test results
testverdicttimescoresubtask
#1--0details
#2ACCEPTED0.04 s1001details
#3ACCEPTED0.58 s1002, 3details
#4ACCEPTED4.39 s874details

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
const int T = 500;

random_device rd;
mt19937 g(rd());

void gen() {
	vector<vector<bool>> v(n, vector<bool>(n, 0));
	for (int i = 0; i < n; i++)
		for (int j = i+1; j < n; j++)
			// v[i][j] = (n + i - j) % n <= (n + j - i) % n, v[j][i] = !v[i][j];
			v[i][j] = g() & 1, v[j][i] = !v[i][j];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cout << v[i][j];
		cout << endl;
	}
}

void solve() {
	vector<vector<int>> Q(n, vector<int>(n, -1));
	auto que = [&](int i, int j) -> bool {
		assert (i != j);
		if (~Q[i][j]) return Q[i][j];
		cout << "? " << i + 1 << ' ' << j + 1 << endl;
		char c; cin >> c;
		Q[i][j] = c == '>';
		Q[j][i] = !Q[i][j];
		return Q[i][j];
	};

	vector<vector<int>> V;
	for (int i = 0; i < n-1; i += 2) {
		V.push_back({i, i+1});
		if (que(i+1, i)) swap(V.back()[0], V.back()[1]);
	}
	int cnt = 0;
	auto split = [&]() -> void {
		cnt = 0;
		do {
			size_t mx = 0;
			for (auto v : V) mx = max(v.size(), mx);
			if (mx < 2) break;
			int i = g() % V.size();
			while (V[i].size() == 1) i = g() % V.size();
			vector<int> w;
			size_t x = g() % (V[i].size() - 1) + 1;
			while (V[i].size() > x) w.push_back(V[i].back()), V[i].pop_back();
			reverse(w.begin(), w.end());
			V.push_back(w);
			shuffle(V.begin(), V.end(), g);
		}
		while (g() & 1);
	};
	while (1) {
		if (V.size() == 1) {
			if (que(V[0].back(), V[0].front())) break;
			split();
			continue;
		}
		if (cnt >= T) {
			split();
			continue;
		}
		int i = g() % V.size(), j = i;
		while (j == i) j = g() % V.size();
		if (que(V[i].back(), V[j].front())) {
			for (int x : V[j]) V[i].push_back(x);
			V.erase(V.begin() + j);
			cnt = 0;
		}
		else cnt++;
	}
	cout << '!';
	for (int x : V[0]) cout << ' ' << x + 1;
	cout << endl;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t; cin >> n >> t;
	gen();
	while (t--) solve();
}

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: ACCEPTED

input
01 4 200 rnd

correct output
(empty)

user output
Activating encoder mode
4 200
0011
1001
0100
...

Feedback: Q = 4.690000

Test 3

Subtask: 2, 3

Verdict: ACCEPTED

input
02 50 200 rnd

correct output
(empty)

user output
Activating encoder mode
50 200
001011001001000000111010010001...

Feedback: Q = 98.450000

Test 4

Subtask: 4

Verdict: ACCEPTED

input
03 500 200 rnd

correct output
(empty)

user output
Activating encoder mode
500 200
010101000001100011000010110011...

Feedback: Q = 775.395000