Submission details
Task:Hamilton
Sender:Sebastian
Submission time:2026-04-17 10:58:00 +0300
Language:C++ (C++20)
Status:READY
Result:5
Feedback
subtaskverdictscore
#1ACCEPTED5
#20
#30
#40
Test results
testverdicttimescoresubtask
#10.01 s0details
#2ACCEPTED0.04 s1001details
#30.01 s02, 3details
#40.01 s04details

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
mt19937 mt(time(0));

// --- JUDGE ---

ll judge_query_count;
vector<vector<bool>> judge_graph;

void judge_init(ll n) {
    cout << "0110\n";
    cout << "0011\n";
    cout << "0001\n";
    cout << "1000" << endl;
}

// true iff u -> v (1-indexed)
bool judge_query(ll u, ll v) {
    assert(u != v);
    judge_query_count++;
    cout << "? " << u << ' ' << v << endl;
    char ans; cin >> ans;
    return ans == '>';
}

// --- CONTESTANT ---

map<pair<ll, ll>, bool> mem;
bool ask(ll u, ll v) {
    if (u > v) return !ask(v, u);
    if (mem.count({u, v})) return mem[{u, v}];
    return mem[{u, v}] = judge_query(u+1, v+1);
}

void solve(ll n) {
    mem.clear();

    vector<ll> a(n);
    iota(all(a), 0ll);
    do {
        bool ok = true;
        for (ll i = 0; i < n; i++) {
            if (!ask(a[i], a[(i+1)%n])) ok = false;
        }
        if (!ok) continue;

        cout << "!";
        for (auto &e : a) cout << ' ' << e+1;
        cout << endl;
        return;
    } while (next_permutation(all(a)));
    assert(false);
}

// --- TESTS ---

int main() {
    ll n, t; cin >> n >> t;
    judge_init(n);
    for (ll i = 0; i < t; i++) {
        solve(n);
    }
}

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
0110
0011
0001
...

Feedback: Self-loop

Test 2

Subtask: 1

Verdict: ACCEPTED

input
01 4 200 rnd

correct output
(empty)

user output
Activating encoder mode
4 200
0110
0011
0001
...

Feedback: Q = 5.600000

Test 3

Subtask: 2, 3

Verdict:

input
02 50 200 rnd

correct output
(empty)

user output
Activating encoder mode
50 200
0110
0011
0001
...

Feedback: Invalid character in graph description63.

Test 4

Subtask: 4

Verdict:

input
03 500 200 rnd

correct output
(empty)

user output
Activating encoder mode
500 200
0110
0011
0001
...

Feedback: Invalid character in graph description63.