#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
void Solve(int N) {
vector<vector<int>> adj(2 * N + 1);
auto hasEdge = [&](int v, vector<int> p) {
p.emplace_back(v);
return Query(p) != p.size();
};
for (int v = 1; v <= 2 * N; ++v) {
vector<int> color(2 * N + 1, -1);
vector<vector<int>> byColor(2);
function<void(int)> dfs = [&](int v) {
for (int u : adj[v]) {
if (color[u] == -1) {
color[u] = color[v] ^ 1;
dfs(u);
}
}
};
for (int i = 1; i < v; ++i) {
if (color[i] == -1) { color[i] = 0; dfs(i); }
byColor[color[i]].emplace_back(i);
}
for (auto &p : byColor) {
while (hasEdge(v, p)) {
int low = 0, high = p.size() - 1;
while (low < high) {
int mid = (low + high) >> 1;
if (hasEdge(v, vector<int>(p.begin(), p.begin() + mid + 1))) {
high = mid;
} else {
low = mid + 1;
}
}
adj[v].emplace_back(p[low]);
adj[p[low]].emplace_back(v);
p = vector<int>(p.begin() + low + 1, p.end());
}
}
}
vector<int> prv(2 * N + 1, -1);
vector<int> nxt(2 * N + 1, -1);
vector<int> mt(2 * N + 1, -1);
for (int v = 1; v <= 2 * N; ++v) {
if (adj[v].size() == 1) {
mt[v] = adj[v][0];
} else {
int u = -1;
if (Query({v, adj[v][0], adj[v][1]}) == 1) u = adj[v][2];
if (Query({v, adj[v][1], adj[v][2]}) == 1) u = adj[v][0];
if (Query({v, adj[v][2], adj[v][0]}) == 1) u = adj[v][1];
nxt[v] = u; prv[u] = v;
}
}
for (int v = 1; v <= 2 * N; ++v) {
if (adj[v].size() == 3) {
mt[v] = adj[v][0] ^ adj[v][1] ^ adj[v][2] ^ prv[v] ^ nxt[v];
}
if (v < mt[v]) Answer(v, mt[v]);
}
}
Compilation message
chameleon.cpp: In lambda function:
chameleon.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
return Query(p) != p.size();
~~~~~~~~~^~~~~~~~~~~
# |
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 |
43 ms |
384 KB |
Output is correct |
4 |
Correct |
43 ms |
384 KB |
Output is correct |
5 |
Correct |
44 ms |
384 KB |
Output is correct |
6 |
Correct |
45 ms |
384 KB |
Output is correct |
7 |
Correct |
47 ms |
384 KB |
Output is correct |
8 |
Correct |
44 ms |
432 KB |
Output is correct |
9 |
Correct |
43 ms |
384 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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 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 |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
69 ms |
384 KB |
Output is correct |
4 |
Correct |
70 ms |
504 KB |
Output is correct |
5 |
Correct |
69 ms |
384 KB |
Output is correct |
6 |
Correct |
70 ms |
384 KB |
Output is correct |
7 |
Correct |
68 ms |
384 KB |
Output is correct |
8 |
Correct |
69 ms |
432 KB |
Output is correct |
9 |
Correct |
75 ms |
760 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 |
43 ms |
384 KB |
Output is correct |
4 |
Correct |
43 ms |
384 KB |
Output is correct |
5 |
Correct |
44 ms |
384 KB |
Output is correct |
6 |
Correct |
45 ms |
384 KB |
Output is correct |
7 |
Correct |
47 ms |
384 KB |
Output is correct |
8 |
Correct |
44 ms |
432 KB |
Output is correct |
9 |
Correct |
43 ms |
384 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 |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 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 |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
6 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
69 ms |
384 KB |
Output is correct |
31 |
Correct |
70 ms |
504 KB |
Output is correct |
32 |
Correct |
69 ms |
384 KB |
Output is correct |
33 |
Correct |
70 ms |
384 KB |
Output is correct |
34 |
Correct |
68 ms |
384 KB |
Output is correct |
35 |
Correct |
69 ms |
432 KB |
Output is correct |
36 |
Correct |
75 ms |
760 KB |
Output is correct |
37 |
Correct |
71 ms |
384 KB |
Output is correct |
38 |
Correct |
44 ms |
384 KB |
Output is correct |
39 |
Correct |
71 ms |
384 KB |
Output is correct |
40 |
Correct |
70 ms |
384 KB |
Output is correct |
41 |
Correct |
71 ms |
384 KB |
Output is correct |
42 |
Correct |
45 ms |
384 KB |
Output is correct |
43 |
Correct |
69 ms |
384 KB |
Output is correct |
44 |
Correct |
71 ms |
384 KB |
Output is correct |
45 |
Correct |
70 ms |
504 KB |
Output is correct |