#include "chameleon.h"
#include <vector>
#include <algorithm>
#include <cassert>
#include <array>
#include <iostream>
using namespace std;
void Solve(int N)
{
N *= 2;
vector<vector<int>> groups;
vector<vector<int>> adj(N + 1);
vector<int> to(N + 1, 0);
vector<int> same(N + 1, 0);
auto ask = [&](vector<int> vec, int x) -> bool {
vec.push_back(x);
return Query(vec) == (int) vec.size();
};
auto find_neighbor = [&](vector<int> vec, int x) -> int {
if (ask(vec, x)) return 0;
while ((int) vec.size() > 1) {
int mid = (int) vec.size() / 2;
if (ask(vector<int>(vec.begin(), vec.begin() + mid), x)) {
vec.erase(vec.begin(), vec.begin() + mid);
} else {
vec.erase(vec.begin() + mid, vec.end());
}
}
return vec[0];
};
for (int x = 1; x <= N; ++x) {
int id = -1;
for (int g_id = 0; g_id < (int) groups.size(); ++g_id) {
vector<int> cur = groups[g_id];
int y = 0;
bool in_group = true;
while ((y = find_neighbor(cur, x))) {
adj[x].push_back(y);
adj[y].push_back(x);
in_group = false;
cur.erase(find(cur.begin(), cur.end(), y));
}
if (in_group) id = g_id;
}
if (!~id) { groups.push_back(vector<int>{x}); }
else groups[id].push_back(x);
}
assert((int) groups.size() <= 4);
for (int x = 1; x <= N; ++x) {
if ((int) adj[x].size() == 1) {
if (!same[x]) {
same[x] = adj[x][0];
same[adj[x][0]] = x;
}
} else {
assert((int) adj[x].size() == 3);
to[x] = adj[x][0];
for (int k = 1; k <= 2; ++k) {
vector<int> vec = adj[x];
vec.erase(vec.begin() + k);
vec.push_back(x);
if (Query(vec) == 1) {
to[x] = adj[x][k];
break;
}
}
for (int p = x, u = to[x]; u != x; p = u, u = to[u]) { // find to[u], same[u]
assert((int) adj[u].size() == 3);
vector<int> candidates;
for (int i : adj[u]) {
if (i != same[u] && i != p) candidates.push_back(i);
}
if ((int) candidates.size() == 1) {
assert(same[u]);
to[u] = candidates[0];
} else {
assert(!same[u]);
assert((int) candidates.size() == 2);
if (Query(vector<int> {candidates[0], p, u}) == 1) {
same[u] = candidates[0], to[u] = candidates[1];
} else {
same[u] = candidates[1], to[u] = candidates[0];
}
}
}
if (!same[x]) {
for (int i : adj[x]) {
if (i != to[x] && to[i] != x) assert(!same[x]), same[x] = i;
}
assert(same[x]);
}
}
}
for (int x = 1; x <= N; ++x) {
assert(same[x]);
if (x < same[x]) Answer(x, same[x]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
4 |
Correct |
22 ms |
384 KB |
Output is correct |
5 |
Correct |
23 ms |
384 KB |
Output is correct |
6 |
Correct |
22 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
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 |
72 ms |
456 KB |
Output is correct |
4 |
Correct |
58 ms |
384 KB |
Output is correct |
5 |
Correct |
80 ms |
384 KB |
Output is correct |
6 |
Correct |
106 ms |
384 KB |
Output is correct |
7 |
Correct |
74 ms |
384 KB |
Output is correct |
8 |
Correct |
70 ms |
460 KB |
Output is correct |
9 |
Correct |
64 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
4 |
Correct |
22 ms |
384 KB |
Output is correct |
5 |
Correct |
23 ms |
384 KB |
Output is correct |
6 |
Correct |
22 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
384 KB |
Output is correct |
8 |
Correct |
23 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
7 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
72 ms |
456 KB |
Output is correct |
31 |
Correct |
58 ms |
384 KB |
Output is correct |
32 |
Correct |
80 ms |
384 KB |
Output is correct |
33 |
Correct |
106 ms |
384 KB |
Output is correct |
34 |
Correct |
74 ms |
384 KB |
Output is correct |
35 |
Correct |
70 ms |
460 KB |
Output is correct |
36 |
Correct |
64 ms |
384 KB |
Output is correct |
37 |
Correct |
62 ms |
384 KB |
Output is correct |
38 |
Correct |
23 ms |
384 KB |
Output is correct |
39 |
Correct |
84 ms |
384 KB |
Output is correct |
40 |
Correct |
69 ms |
384 KB |
Output is correct |
41 |
Correct |
66 ms |
384 KB |
Output is correct |
42 |
Correct |
23 ms |
384 KB |
Output is correct |
43 |
Correct |
68 ms |
384 KB |
Output is correct |
44 |
Correct |
62 ms |
504 KB |
Output is correct |
45 |
Correct |
59 ms |
384 KB |
Output is correct |