#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
#define MAX 1010
namespace {
vector<int> adj[MAX];
vector<int> vs[2][MAX];
bool find(vector<int>& v, int x) {
int l;
for (l = 0; l < v.size(); l++) if (v[l] == x) return true;
return false;
}
int nxt[MAX];
int rev[MAX];
}
void Solve(int N) {
int i, j;
vs[0][0].push_back(1);
int cnt = 1;
for (i = 2; i <= N * 2; i++) {
vector<int> v[2];
int l, r;
vector<int> rv; // adjacent vertex
vector<int> qv;
for (auto c : { 0, 1 }) {
for (j = 0; j < cnt; j++) for (auto x : vs[c][j]) v[c].push_back(x);
while (v[c].size()) {
qv = v[c];
qv.push_back(i);
if (Query(qv) == qv.size()) break;
l = 0, r = qv.size();
while (r - l > 1) {
int m = l + r >> 1;
qv = v[c];
qv.resize(m);
qv.push_back(i);
if (Query(qv) < qv.size()) r = m;
else l = m;
}
rv.push_back(v[c][r - 1]);
v[c].erase(v[c].begin() + r - 1);
}
}
for (auto v : rv) adj[v].push_back(i), adj[i].push_back(v);
for (j = 0; j < cnt; j++) {
int c = 0;
for (auto v : vs[0][j]) {
if (find(rv, v)) {
c = 1;
break;
}
}
if (c) swap(vs[0][j], vs[1][j]);
}
int pv = -1;
for (j = 0; j < cnt; j++) {
int c = 0;
for (auto v : vs[1][j]) {
if (find(rv, v)) {
c = 1;
break;
}
}
if (c) {
if (!~pv) vs[0][j].push_back(i), pv = j;
else {
for (auto x : vs[0][j]) vs[0][pv].push_back(x);
for (auto x : vs[1][j]) vs[1][pv].push_back(x);
vs[0][j].clear();
vs[1][j].clear();
}
}
}
if (!~pv) vs[0][cnt++].push_back(i);
for (j = 1; j < cnt; j++) if (vs[0][j - 1].empty() && vs[1][j - 1].empty()) {
swap(vs[0][j], vs[0][j - 1]);
swap(vs[1][j], vs[1][j - 1]);
}
l = 0;
for (j = 0; j < cnt; j++) if (vs[0][j].size() || vs[1][j].size()) l = j;
cnt = l + 1;
}
for (i = 1; i <= N * 2; i++) {
assert(adj[i].size() == 3 || adj[i].size() == 1);
if (adj[i].size() == 1) continue;
int res1 = Query({ i, adj[i][0], adj[i][1] });
int res2 = Query({ i, adj[i][0], adj[i][2] });
if (res1 == 1) nxt[i] = adj[i][2];
else if (res2 == 1) nxt[i] = adj[i][1];
else nxt[i] = adj[i][0];
rev[nxt[i]] = i;
}
for (i = 1; i <= N * 2; i++) {
int l;
for (auto v : adj[i]) {
if (v == nxt[i]) continue;
if (v == rev[i]) continue;
l = v;
}
if (i < l) Answer(i, l);
}
}
Compilation message
chameleon.cpp: In function 'bool {anonymous}::find(std::vector<int>&, int)':
chameleon.cpp:11:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (l = 0; l < v.size(); l++) if (v[l] == x) return true;
| ~~^~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if (Query(qv) == qv.size()) break;
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:35:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int m = l + r >> 1;
| ~~^~~
chameleon.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if (Query(qv) < qv.size()) r = m;
| ~~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:102:20: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
102 | if (i < l) Answer(i, l);
| ~~~~~~^~~~~~
# |
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 |
12 ms |
592 KB |
Output is correct |
4 |
Correct |
13 ms |
600 KB |
Output is correct |
5 |
Correct |
20 ms |
600 KB |
Output is correct |
6 |
Correct |
13 ms |
600 KB |
Output is correct |
7 |
Correct |
12 ms |
600 KB |
Output is correct |
8 |
Correct |
13 ms |
600 KB |
Output is correct |
9 |
Correct |
14 ms |
600 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 |
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 |
0 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 |
0 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 |
0 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 |
540 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 |
25 ms |
600 KB |
Output is correct |
4 |
Correct |
25 ms |
600 KB |
Output is correct |
5 |
Correct |
25 ms |
600 KB |
Output is correct |
6 |
Correct |
25 ms |
600 KB |
Output is correct |
7 |
Correct |
39 ms |
596 KB |
Output is correct |
8 |
Correct |
28 ms |
604 KB |
Output is correct |
9 |
Correct |
30 ms |
604 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 |
12 ms |
592 KB |
Output is correct |
4 |
Correct |
13 ms |
600 KB |
Output is correct |
5 |
Correct |
20 ms |
600 KB |
Output is correct |
6 |
Correct |
13 ms |
600 KB |
Output is correct |
7 |
Correct |
12 ms |
600 KB |
Output is correct |
8 |
Correct |
13 ms |
600 KB |
Output is correct |
9 |
Correct |
14 ms |
600 KB |
Output is correct |
10 |
Correct |
0 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 |
0 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 |
0 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 |
540 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 |
25 ms |
600 KB |
Output is correct |
31 |
Correct |
25 ms |
600 KB |
Output is correct |
32 |
Correct |
25 ms |
600 KB |
Output is correct |
33 |
Correct |
25 ms |
600 KB |
Output is correct |
34 |
Correct |
39 ms |
596 KB |
Output is correct |
35 |
Correct |
28 ms |
604 KB |
Output is correct |
36 |
Correct |
30 ms |
604 KB |
Output is correct |
37 |
Correct |
23 ms |
600 KB |
Output is correct |
38 |
Correct |
12 ms |
600 KB |
Output is correct |
39 |
Correct |
31 ms |
616 KB |
Output is correct |
40 |
Correct |
22 ms |
608 KB |
Output is correct |
41 |
Correct |
22 ms |
600 KB |
Output is correct |
42 |
Correct |
12 ms |
600 KB |
Output is correct |
43 |
Correct |
25 ms |
604 KB |
Output is correct |
44 |
Correct |
23 ms |
600 KB |
Output is correct |
45 |
Correct |
23 ms |
600 KB |
Output is correct |