| Task: | Hamilton |
| Sender: | Asarbardjarn |
| Submission time: | 2026-04-17 11:58:20 +0300 |
| Language: | C++ (C++23) |
| Status: | READY |
| Result: | 86 |
| subtask | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 5 |
| #2 | ACCEPTED | 7 |
| #3 | ACCEPTED | 12 |
| #4 | ACCEPTED | 62 |
| test | verdict | time | score | subtask | |
|---|---|---|---|---|---|
| #1 | WRONG ANSWER | 0.01 s | 0 | details | |
| #2 | ACCEPTED | 0.04 s | 100 | 1 | details |
| #3 | ACCEPTED | 0.59 s | 100 | 2, 3 | details |
| #4 | ACCEPTED | 4.65 s | 82 | 4 | details |
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
const int T = 500;
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 << 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];
};
random_device rd;
mt19937 g(rd());
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: WRONG ANSWER
| 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: Formatting error
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 000000000000000000000000011111... |
Feedback: Q = 97.510000
Test 4
Subtask: 4
Verdict: ACCEPTED
| input |
|---|
| 03 500 200 rnd |
| correct output |
|---|
| (empty) |
| user output |
|---|
| Activating encoder mode 500 200 000000000000000000000000000000... |
Feedback: Q = 790.390000
