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

Code

#include <bits/stdc++.h>

using namespace std;

int n;

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];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cout << v[i][j];
		cout << '\n';
	}
}

void solve() {
	vector<vector<int>> Q(n, vector<int>(n, -1));
	auto que = [&](int i, int j) -> bool {
		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];
	};
	int cnt = 0;
	queue<pair<int, vector<int>>> q;

	random_device rd;
	mt19937 g(rd());
	auto rebuild = [&]() -> void {
		vector<vector<int>> A;
		A.reserve(q.size());
		while (q.size()) {
			auto [_, v] = q.front(); q.pop();
			A.push_back(v);
		}
		shuffle(A.begin(), A.end(), g);
		vector<int> v = A.back(); A.pop_back();
		int s = g() % (v.size() + 1);
		vector<int> L, R;
		for (int i = 0; i < (int)v.size(); i++) (i < s ? L : R).push_back(v[i]);
		if (L.size()) A.push_back(L);
		if (R.size()) A.push_back(R);
		shuffle(A.begin(), A.end(), g);
		cnt = 0;
		for (auto w : A) q.push({cnt-1, w});
	};

	for (int i = 0; i < n; i++) q.push({cnt-1, vector<int>(1, i)});
	while (q.size() > 1) {
		auto [i, v] = q.front(); q.pop();
		auto [j, w] = q.front(); q.pop();
		if (j >= cnt) {
			q.push({i, v});
			q.push({j, w});
			rebuild();
			continue;
		}
		if (que(v.back(), w.front())) {
			for (int x : w) v.push_back(x);
			q.push({cnt++, v});
		}
		else if (que(w.back(), v.front())) {
			for (int x : v) w.push_back(x);
			q.push({cnt++, w});
		}
		else {
			if (g() & 1) swap(v, w);
			q.push({cnt, v});
			q.push({cnt, w});
		}
	}
	cout << '!';
	for (int x : q.front().second) 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
Activating encoder mode
5 2
00011
10001
11000
...

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

Test 2

Subtask: 1

Verdict:

input
01 4 200 rnd

correct output
(empty)

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

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

Test 3

Subtask: 2, 3

Verdict:

input
02 50 200 rnd

correct output
(empty)

user output
Activating encoder mode
50 200
000000000000000000000000011111...

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

Test 4

Subtask: 4

Verdict:

input
03 500 200 rnd

correct output
(empty)

user output
Activating encoder mode
500 200
000000000000000000000000000000...

Feedback: Case #1: Wrong edge in answer, 190 to 498