#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
vector< vector<int> > g;
vector<int> found, st;
void find(const vector<int>& v, int cur) {
vector<int> tmp = v;
tmp.push_back(cur);
if (Query(tmp) == (int) tmp.size()) {
return;
}
if ((int) v.size() == 1) {
found.push_back(v[0]);
return;
}
vector<int> a, b;
for (int i = 0; i < (int) v.size(); i++) {
if (i % 2 == 0) {
a.push_back(v[i]);
} else {
b.push_back(v[i]);
}
}
find(a, cur);
find(b, cur);
}
}
void Solve(int N) {
g.resize(2 * N + 1);
st.resize(2 * N + 1);
st[1] = 0;
for (int i = 2; i <= 2 * N; i++) {
found.clear();
vector<int> a, b;
for (int j = 1; j < i; j++) {
if (st[j] == 0) {
a.push_back(j);
} else {
b.push_back(j);
}
}
find(a, i);
find(b, i);
if (found.empty()) {
st[i] = 0;
} else {
for (auto& x : found) {
st[i] = !st[x];
g[i].push_back(x);
g[x].push_back(i);
}
}
}
vector<int> used(2 * N + 1, 0), in(2 * N + 1), out(2 * N + 1);
for (int i = 1; i <= 2 * N; i++) {
if (used[i]) {
continue;
}
if ((int) g[i].size() == 1) {
Answer(i, g[i][0]);
used[i] = used[g[i][0]] = 1;
} else {
if (Query({i, g[i][0], g[i][1]}) == 1) {
out[i] = g[i][2];
in[g[i][2]] = i;
} else {
if (Query({i, g[i][0], g[i][2]}) == 1) {
out[i] = g[i][1];
in[g[i][1]] = i;
} else {
out[i] = g[i][0];
in[g[i][0]] = i;
}
}
}
}
for (int i = 1; i <= 2 * N; i++) {
if (used[i]) {
continue;
}
for (auto& x : g[i]) {
if (x != in[i] && x != out[i]) {
Answer(i, x);
used[i] = used[x] = 1;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
41 ms |
384 KB |
Output is correct |
4 |
Correct |
37 ms |
384 KB |
Output is correct |
5 |
Correct |
38 ms |
384 KB |
Output is correct |
6 |
Correct |
37 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
42 ms |
384 KB |
Output is correct |
9 |
Correct |
38 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [5] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [5] |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Incorrect |
54 ms |
384 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
41 ms |
384 KB |
Output is correct |
4 |
Correct |
37 ms |
384 KB |
Output is correct |
5 |
Correct |
38 ms |
384 KB |
Output is correct |
6 |
Correct |
37 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
42 ms |
384 KB |
Output is correct |
9 |
Correct |
38 ms |
456 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [5] |
18 |
Halted |
0 ms |
0 KB |
- |