#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int ask(vector<int> b) {
for (auto& e : b) e += 1;
int res = Query(b);
return res;
}
int ask_ref(vector<int>& b) {
for (auto& e : b) e += 1;
int res = Query(b);
for (auto& e : b) e -= 1;
return res;
}
int same_col(int a, vector<int>& b) {
if (b.size() == 1) return b.front();
vector<int> bl, br;
for (int i = 0; i < b.size(); ++i) {
(i % 2 ? bl : br).push_back(b[i]);
}
int bl_c = ask_ref(bl);
bl.push_back(a);
int bla_c = ask_ref(bl);
bl.pop_back();
if (bla_c == bl_c) return same_col(a, bl);
return same_col(a, br);
}
// The lower function but only one is currently in b (and the other is in other)
int find_two_single(int a, vector<int>& other, vector<int>& b) {
if (b.size() == 1) return b.front();
vector<int> bl, br;
for (int i = 0; i < b.size(); ++i) {
(i % 2 ? bl : br).push_back(b[i]);
}
bl.push_back(a);
for (auto o : other) bl.push_back(o);
int blao_c = ask_ref(bl);
for (auto _ : other) bl.pop_back();
bl.pop_back();
if (blao_c == bl.size() + other.size() - 1) {
return find_two_single(a, other, bl);
} else {
return find_two_single(a, other, br);
}
}
// The lower function but a is guaranteed to not be in a C_2
pair<int, int> find_two_inner(int a, vector<int>& b) {
if (b.size() == 2) return {b[0], b[1]};
vector<int> bl, br;
for (int i = 0; i < b.size(); ++i) {
(i % 2 ? bl : br).push_back(b[i]);
}
bl.push_back(a);
int bla_c = ask_ref(bl);
bl.pop_back();
if (bla_c == bl.size() - 1) {
return find_two_inner(a, bl);
}
br.push_back(a);
int bra_c = ask_ref(br);
br.pop_back();
if (bra_c == br.size() - 1) {
return find_two_inner(a, br);
}
// bla_c and bra_c is split
int fst = find_two_single(a, bl, br);
int snd = find_two_single(a, br, bl);
return {fst, snd};
}
int n;
// given a node, finds one loving this and one with the same color as this
// in case this belongs to a C_2, then only the one with the same color is returned
// TODO: un-assume 0 <= a < n
pair<int, int> find_two(int a) {
vector<int> b;
if (a < n) {
for (int i = n; i < 2 * n; ++i) b.push_back(i);
} else {
for (int i = 0; i < n; ++i) b.push_back(i);
}
b.push_back(a);
int total_cnt = ask(b);
b.pop_back();
assert(total_cnt == n - 1 || total_cnt == n);
if (total_cnt == n) {
// This belongs to a C_2
return {same_col(a, b), -1};
}
// This belongs to a larger cycle
return find_two_inner(a, b);
}
} // namespace
void Solve(int _n) {
::n = _n;
vector<int> b(2 * n, 0);
iota(b.begin(), b.end(), 0);
vector<vector<int>> adj(2 * n);
for (int i = 0; i < 2 * n; ++i) {
auto [a, b] = find_two(i);
adj[i] = {a, b};
}
// Any double edges mean that they are the same color
set<pair<int, int>> saw;
for (int i = 0; i < 2 * n; ++i) {
for (auto j : adj[i]) {
if (saw.count({i, j}) || saw.count({j, i})) {
Answer(i + 1, j + 1);
} else {
saw.insert({i, j});
}
}
}
}
#ifndef EVAL
#include "grader.cpp"
#endif
Compilation message
chameleon.cpp: In function 'int {anonymous}::same_col(int, std::vector<int>&)':
chameleon.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < b.size(); ++i) {
| ~~^~~~~~~~~~
chameleon.cpp: In function 'int {anonymous}::find_two_single(int, std::vector<int>&, std::vector<int>&)':
chameleon.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0; i < b.size(); ++i) {
| ~~^~~~~~~~~~
chameleon.cpp:44:15: warning: unused variable '_' [-Wunused-variable]
44 | for (auto _ : other) bl.pop_back();
| ^
chameleon.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if (blao_c == bl.size() + other.size() - 1) {
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp: In function 'std::pair<int, int> {anonymous}::find_two_inner(int, std::vector<int>&)':
chameleon.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < b.size(); ++i) {
| ~~^~~~~~~~~~
chameleon.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | if (bla_c == bl.size() - 1) {
| ~~~~~~^~~~~~~~~~~~~~~~
chameleon.cpp:73:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if (bra_c == br.size() - 1) {
| ~~~~~~^~~~~~~~~~~~~~~~
# |
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 |
Runtime error |
0 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
600 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
0 ms |
600 KB |
Execution killed with signal 6 |
3 |
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 |
34 ms |
508 KB |
Output is correct |
4 |
Correct |
35 ms |
344 KB |
Output is correct |
5 |
Correct |
35 ms |
344 KB |
Output is correct |
6 |
Correct |
45 ms |
524 KB |
Output is correct |
7 |
Correct |
37 ms |
520 KB |
Output is correct |
8 |
Correct |
35 ms |
508 KB |
Output is correct |
9 |
Correct |
35 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 |
Runtime error |
0 ms |
600 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |