// https://codeforces.com/blog/entry/74871?#comment-591244
#include <bits/stdc++.h>
#include "chameleon.h"
using namespace std;
namespace {
ostream &operator << (ostream &os, vector<int> v) {
for (int i = 0; i < v.size(); ++i) {
os << (i ? ", " : "") << i;
}
return os;
}
void __print() {
cerr << "]\n";
}
template<class T, class... V>
void __print(T t, V... v) {
cerr << t;
if (sizeof...(v)) {
cerr << ", ";
}
__print(v...);
}
#define debug(x...) cerr << "[" << #x << "] = ["; __print(x);
}
void Solve(int N) {
vector<vector<int>> g(2 * N);
auto add = [&](int a, int b) {
g[a].push_back(b);
g[b].push_back(a);
};
vector<int> c(2 * N, -1);
auto dfs = [&](auto dfs, int u) -> void {
for (int v : g[u]) {
if (c[v] == -1) {
c[v] = c[u] ^ 1;
dfs(dfs, v);
} else {
assert(c[v] == 1 - c[u]);
}
}
};
array<vector<int>, 2> cands;
auto color = [&](int p) {
fill(c.begin(), c.end(), -1);
for (auto it : {0, 1}) {
cands[it].clear();
}
for (int i = 0; i < p; ++i) {
if (c[i] == -1) {
c[i] = 0;
dfs(dfs, i);
}
cands[c[i]].push_back(i + 1);
}
};
auto check = [&](vector<int> v, int p) {
v.push_back(p + 1);
assert(v.size() > 1);
return Query(v) != v.size();
};
for (int i = 1; i < 2 * N; ++i) {
color(i);
for (auto it : {0, 1}) {
while (cands[it].size() && check(cands[it], i)) {
int L = 0, R = cands[it].size() - 1, p = -1;
while (L <= R) {
int md = (L + R) / 2;
if (check(vector<int>(cands[it].begin(), cands[it].begin() + md + 1), i)) {
p = md;
R = md - 1;
} else {
L = md + 1;
}
}
assert(~p);
add(i, cands[it][p] - 1);
cands[it] = vector<int>(cands[it].begin() + p + 1, cands[it].end());
}
}
}
auto nxt = [&](int x, int y) {
if ((x += y) >= 3) {
x -= 3;
}
if (x < 0) {
x += 3;
}
return x;
};
vector<int> res(2 * N);
for (int i = 0; i < 2 * N; ++i) {
for (int x : g[i]) {
res[i] += x;
}
if (g[i].size() == 3) {
for (int j = 0; j < 3; ++j) {
if (Query({i + 1, g[i][j] + 1, g[i][nxt(j, 1)] + 1}) == 1) {
int p = g[i][nxt(j, -1)];
res[i] -= p;
res[p] -= i;
}
}
}
}
for (int i = 0; i < 2 * N; ++i) {
if (i < res[i]) {
Answer(i + 1, res[i] + 1);
}
}
}
Compilation message
chameleon.cpp: In function 'std::ostream& {anonymous}::operator<<(std::ostream&, std::vector<int>)':
chameleon.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
chameleon.cpp: In lambda function:
chameleon.cpp:67:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | return Query(v) != v.size();
| ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: At global scope:
chameleon.cpp:17:8: warning: 'void {anonymous}::__print()' defined but not used [-Wunused-function]
17 | void __print() {
| ^~~~~~~
chameleon.cpp:10:12: warning: 'std::ostream& {anonymous}::operator<<(std::ostream&, std::vector<int>)' defined but not used [-Wunused-function]
10 | ostream &operator << (ostream &os, vector<int> v) {
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
14 ms |
576 KB |
Output is correct |
4 |
Correct |
17 ms |
588 KB |
Output is correct |
5 |
Correct |
19 ms |
476 KB |
Output is correct |
6 |
Correct |
14 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
584 KB |
Output is correct |
8 |
Correct |
14 ms |
344 KB |
Output is correct |
9 |
Correct |
15 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
29 ms |
600 KB |
Output is correct |
4 |
Correct |
30 ms |
600 KB |
Output is correct |
5 |
Correct |
28 ms |
540 KB |
Output is correct |
6 |
Correct |
28 ms |
612 KB |
Output is correct |
7 |
Correct |
28 ms |
600 KB |
Output is correct |
8 |
Correct |
31 ms |
604 KB |
Output is correct |
9 |
Correct |
28 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
14 ms |
576 KB |
Output is correct |
4 |
Correct |
17 ms |
588 KB |
Output is correct |
5 |
Correct |
19 ms |
476 KB |
Output is correct |
6 |
Correct |
14 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
584 KB |
Output is correct |
8 |
Correct |
14 ms |
344 KB |
Output is correct |
9 |
Correct |
15 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
29 ms |
600 KB |
Output is correct |
31 |
Correct |
30 ms |
600 KB |
Output is correct |
32 |
Correct |
28 ms |
540 KB |
Output is correct |
33 |
Correct |
28 ms |
612 KB |
Output is correct |
34 |
Correct |
28 ms |
600 KB |
Output is correct |
35 |
Correct |
31 ms |
604 KB |
Output is correct |
36 |
Correct |
28 ms |
344 KB |
Output is correct |
37 |
Correct |
29 ms |
600 KB |
Output is correct |
38 |
Correct |
14 ms |
344 KB |
Output is correct |
39 |
Correct |
31 ms |
596 KB |
Output is correct |
40 |
Correct |
33 ms |
576 KB |
Output is correct |
41 |
Correct |
29 ms |
608 KB |
Output is correct |
42 |
Correct |
14 ms |
344 KB |
Output is correct |
43 |
Correct |
28 ms |
584 KB |
Output is correct |
44 |
Correct |
29 ms |
600 KB |
Output is correct |
45 |
Correct |
29 ms |
600 KB |
Output is correct |