#include <bits/stdc++.h>
#include "chameleon.h"
template <class T>
using Vec = std::vector<T>;
void Solve(int N) {
Vec<Vec<int>> graph(2 * N + 1);
if (N <= 50) {
for (int u = 1; u <= 2 * N; ++u) {
for (int v = u + 1; v <= 2 * N; ++v) {
const auto kinds = Query({ u, v });
if (kinds == 1) {
graph[u].push_back(v);
graph[v].push_back(u);
}
}
}
}
else {
for (int u = 1; u <= N; ++u) {
std::queue<Vec<int>> que;
{
Vec<int> cand(N);
std::iota(cand.begin(), cand.end(), N + 1);
que.push(std::move(cand));
}
while (!que.empty()) {
auto ask = que.front();
que.pop();
ask.push_back(u);
if (Query(ask) == (int) ask.size()) {
continue;
}
ask.pop_back();
if (ask.size() == 1) {
graph[u].push_back(ask.front());
graph[ask.front()].push_back(u);
continue;
}
const int m = (int) ask.size() / 2;
Vec<int> left(ask.begin(), ask.begin() + m);
Vec<int> right(ask.begin() + m, ask.end());
que.push(std::move(left));
que.push(std::move(right));
}
}
}
Vec<Vec<int>> prob(2 * N + 1, Vec<int>(2 * N + 1));
for (int u = 1; u <= 2 * N; ++u) {
if (graph[u].size() == 1) {
prob[u][graph[u].front()] = true;
}
else {
assert(graph[u].size() == 3);
for (int ignore = 0; ignore < 3; ++ignore) {
if (prob[u][graph[u][ignore]] == 2) {
continue;
}
Vec<int> ask;
ask.push_back(u);
for (int k = 0; k < 3; ++k) {
if (ignore != k) {
ask.push_back(graph[u][k]);
}
}
if (Query(ask) == 2) {
prob[u][graph[u][ignore]] = 1;
}
else {
prob[u][graph[u][ignore]] = 2;
}
}
}
}
for (int u = 1; u <= 2 * N; ++u) {
for (int v = u + 1; v <= 2 * N; ++v) {
if (prob[u][v] == 1 && prob[v][u] == 1) {
Answer(u, v);
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
34 ms |
364 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
2 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Incorrect |
37 ms |
364 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
34 ms |
364 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |