#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
bool bad(vector<int> ask, int v) {
ask.push_back(v);
return Query(ask) != (int) ask.size();
}
void Solve(int N) {
vector<bool> vis(N * 2 + 1);
vector<vector<int>> g(N * 2 + 1);
function<void(int, int, vector<vector<int>>&)> dfs = [&](int v, int parity, vector<vector<int>>& p) {
if (vis[v] == true) {
return;
}
vis[v] = true;
p[parity].push_back(v);
for (int u : g[v]) {
dfs(u, parity ^ 1, p);
}
};
for (int i = 2; i <= 2 * N; ++i) {
vector<vector<int>> p(2);
for (int j = 1; j < i; ++j) {
vis[j] = false;
}
for (int j = 1; j < i; ++j) {
if (!vis[j]) {
dfs(j, 0, p);
}
}
//cerr << "V: " << i << ' ' << p[0].size() << ' ' << p[1].size() << '\n';
for (int rep = 0; rep < 2; ++rep) {
while (true) {
int m = (int) p[rep].size();
int l = -1, r = m - 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
vector<int> ask;
for (int j = 0; j <= mid; ++j) {
ask.push_back(p[rep][j]);
}
if (bad(ask, i)) {
r = mid - 1;
} else {
l = mid;
}
}
if (r == m - 1) {
break;
}
//cerr << "u, v: " << i << ' ' << p[rep][l + 1] << '\n';
g[p[rep][l + 1]].push_back(i);
g[i].push_back(p[rep][l + 1]);
vector<int> np;
for (int j = l + 2; j < m; ++j) {
np.push_back(p[rep][j]);
}
swap(p[rep], np);
}
}
}
vector<bool> f(2 * N + 1);
vector<int> love(2 * N + 1);
for (int v = 1; v <= 2 * N; ++v) {
if (g[v].size() == 1) {
f[v] = true;
f[g[v][0]] = true;
Answer(v, g[v][0]);
continue;
}
assert(g[v].size() == 3);
int x = g[v][0] ^ g[v][1] ^ g[v][2];
for (int i = 0; i < 3 && !love[v]; ++i) {
for (int j = i + 1; j < 3; ++j) {
int u = g[v][i], w = g[v][j];
int k = Query({u, v, w});
if (k == 1) {
love[v] = x ^ u ^ w;
break;
}
}
}
}
for (int v = 1; v <= N * 2; ++v) {
if (f[v]) {
continue;
}
for (int u : g[v]) {
if (u != love[v] && love[u] != v) {
f[u] = true;
Answer(u, v);
break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [5] |
2 |
Halted |
0 ms |
0 KB |
- |