#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int n) {
auto query = [&](vector<int> p) -> int {
for (int &i : p) i++;
return Query(p);
};
auto answer = [&](int i, int j) -> void {
Answer(i + 1, j + 1);
};
auto sum = [&](vector<int> a, vector<int> b) -> vector<int> {
a.insert(a.end(), b.begin(), b.end());
return a;
};
vector<int> p0, p1;
for (int u = 0; u < 2 * n; u++) {
if (query(sum(p0, {u})) == p0.size() + 1) {
p0.push_back(u);
} else {
p1.push_back(u);
}
}
vector<vector<int>> adj(2 * n);
for (int u : p0) {
vector<int> p = p1;
while (true) {
int l = 0, r = p.size();
while (l + 1 < r) {
int m = (l + r) >> 1;
if (query(sum(vector<int>(p.begin() + l, p.begin() + m), {u})) < m - l + 1) {
r = m;
} else {
l = m;
}
}
int v = p[l];
adj[u].push_back(v);
adj[v].push_back(u);
p.erase(p.begin() + l);
if (adj[u].size() == 3 || query(sum(p, {u})) == p.size() + 1) break;
}
}
for (int u = 0; u < 2 * n; u++) {
assert(adj[u].size() == 1 || adj[u].size() == 3);
for (int i = 0; i < 3 && adj[u].size() == 3; i++) {
for (int j = i + 1; j < 3 && adj[u].size() == 3; j++) {
if (query({u, adj[u][i], adj[u][j]}) == 1) {
adj[u] = {adj[u][i], adj[u][j]};
}
}
}
}
for (int u = 0; u < 2 * n; u++) {
for (int v : adj[u]) {
if (find(adj[v].begin(), adj[v].end(), u) != adj[v].end()) {
if (u < v) answer(u, v);
}
}
}
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:20:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (query(sum(p0, {u})) == p0.size() + 1) {
| ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
chameleon.cpp:45:58: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (adj[u].size() == 3 || query(sum(p, {u})) == p.size() + 1) break;
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# |
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 |
9 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
532 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
344 KB |
Output is correct |
8 |
Correct |
9 ms |
344 KB |
Output is correct |
9 |
Correct |
9 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 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
20 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
344 KB |
Output is correct |
5 |
Correct |
21 ms |
540 KB |
Output is correct |
6 |
Correct |
25 ms |
536 KB |
Output is correct |
7 |
Correct |
21 ms |
344 KB |
Output is correct |
8 |
Correct |
21 ms |
344 KB |
Output is correct |
9 |
Correct |
21 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 |
9 ms |
344 KB |
Output is correct |
4 |
Correct |
10 ms |
532 KB |
Output is correct |
5 |
Correct |
9 ms |
344 KB |
Output is correct |
6 |
Correct |
9 ms |
344 KB |
Output is correct |
7 |
Correct |
10 ms |
344 KB |
Output is correct |
8 |
Correct |
9 ms |
344 KB |
Output is correct |
9 |
Correct |
9 ms |
344 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 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
14 |
Halted |
0 ms |
0 KB |
- |