| Task: | Hamilton |
| Sender: | sofapuden |
| Submission time: | 2026-04-17 15:36:52 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 98 |
| subtask | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 5 |
| #2 | ACCEPTED | 7 |
| #3 | ACCEPTED | 12 |
| #4 | ACCEPTED | 74 |
| test | verdict | time | score | subtask | |
|---|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 100 | details | |
| #2 | ACCEPTED | 0.04 s | 100 | 1 | details |
| #3 | ACCEPTED | 0.48 s | 100 | 2, 3 | details |
| #4 | ACCEPTED | 4.44 s | 97 | 4 | details |
Compiler report
input/code.cpp: In function 'void solve(int)':
input/code.cpp:59:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
59 | random_shuffle(perm.begin(), perm.end());
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
from input/code.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:4581:5: note: declared here
4581 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
| ^~~~~~~~~~~~~~Code
#include<bits/stdc++.h>
using namespace std;
vector<string> gr;
int cnt = 0;
vector<int> perm;
vector<vector<int>> mem;
bool que(int u, int v) {
// u = perm[u], v = perm[v];
if(~mem[u][v]) return mem[u][v];
cnt++;
cout << "? " << u + 1 << ' ' << v + 1 << endl;
char c; cin >> c;
// char c = (gr[u][v] == '1' ? '>' : '<');
mem[u][v] = c == '>';
mem[v][u] = !mem[u][v];
return mem[u][v];
}
void ans(vector<int> c) {
cout << "! ";
for(auto x : c) cout << x + 1 << ' ';
cout << endl;
}
void solve4() {
int n = 4;
mem.assign(n, vector<int> (n, -1));
vector<int> c(n);
iota(c.begin(), c.end(), 0);
do {
bool ok = 1;
for(int i = 0; i < n; ++i) {
ok &= que(c[i], c[(i + 1) % n]);
}
if(ok) {
ans(c);
return;
}
} while(next_permutation(c.begin(), c.end()));
}
vector<int> merge(vector<int> a, vector<int> b) {
if(que(a.back(), b[0])) {
for(auto x : b) a.push_back(x);
return a;
}
else if(que(b.back(), a[0])){
for(auto x : a) b.push_back(x);
return b;
}
return {-1};
}
void solve(int n) {
random_shuffle(perm.begin(), perm.end());
mem.assign(n, vector<int> (n, -1));
vector<vector<int>> cu;
for(int i = 0; i < n; ++i) cu.push_back({i});
for(int i = 0; i + 1 < (int)cu.size(); ++i) {
auto z = merge(cu[i], cu[i + 1]);
if(z[0] == -1) continue;
cu[i] = z;
cu.erase(cu.begin() + i + 1);
}
for(int _ = 0; _ < 2000 && cu.size() > 1; ++_) {
int a = rand() % (int)cu.size();
int b = rand() % (int)cu.size();
if(a == b) continue;
auto z = merge(cu[a], cu[b]);
if(z[0] == -1) continue;
cu[a] = z;
cu.erase(cu.begin() + b);
}
sort(cu.begin(), cu.end(), [&](auto a, auto b) { return a.size() > b.size(); });
while(cu.size() > 1) {
for(int i = 0; i < (int)cu[0].size(); ++i) {
if(que(cu[0][i], cu.back()[0]) && que(cu.back().back(), cu[0][i + 1])) {
while(cu.back().size()) {
cu[0].insert(cu[0].begin() + i + 1, cu.back().back());
cu.back().pop_back();
}
break;
}
}
cu.pop_back();
}
auto c = cu[0];
int ls = (int)c.size() - 1;
while(que(c[0], c[ls])) ls--;
ls++;
if(ls < n) {
for(int i = 0; i < ls; ++i) {
if(que(c[i], c[ls]) && que(c.back(), c[i + 1])) {
for(int j = 0; j < (int)c.size() - ls; ++j) {
c.insert(c.begin() + i + 1, c.back());
c.pop_back();
}
break;
}
}
}
for(int i = 0; i < n; ++i) assert(que(c[i], c[(i + 1) % n]));
ans(c);
}
int main() {
srand(501);
int n, t; cin >> n >> t;
perm.resize(n);
iota(perm.begin(), perm.end(), 0);
if(n == 4) {
gr = {"0110", "0011", "0001", "1000"};
cout << "0110\n0011\n0001\n1000" << endl;
while(t--) {
solve4();
}
return 0;
}
gr.resize(n, string(n, '0'));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(i == j) continue;
int x = rand() & 1;
gr[i][j] = '1' - x;
gr[j][i] = '0' + x;
}
}
for(auto x : gr) cout << x << endl;
while(t--) solve(n);
// cerr << cnt << '\n';
}
Test details
Test 1
Subtask:
Verdict: ACCEPTED
| input |
|---|
| 0 5 2 fixed 1 2 3 4 5 2 4 1 5 ... |
| correct output |
|---|
| (empty) |
| user output |
|---|
| Activating encoder mode 5 2 00111 10000 01010 ... |
Feedback: Q = 7.000000
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: ACCEPTED
| input |
|---|
| 02 50 200 rnd |
| correct output |
|---|
| (empty) |
| user output |
|---|
| Activating encoder mode 50 200 011100001000100100101100110011... |
Feedback: Q = 78.120000
Test 4
Subtask: 4
Verdict: ACCEPTED
| input |
|---|
| 03 500 200 rnd |
| correct output |
|---|
| (empty) |
| user output |
|---|
| Activating encoder mode 500 200 000001101101000101011111110000... |
Feedback: Q = 754.440000
