#include "chameleon.h"
#include <cstdio>
#include <cassert>
#include <vector>
const int N = 1000 + 10;
std::vector<int> edges[N];
int col[N];
void dfs(int u, int c) {
if (col[u] != -1) return;
col[u] = c;
for (auto &v: edges[u]) dfs(v, c ^ 1);
}
bool check(std::vector<int> v, int x) {
v.push_back(x);
return Query(v) == v.size();
}
void Solve(int N) {
for (int i = 1; i <= N * 2; ++i) {
for (int j = 1; j < i; ++j) col[j] = -1;
for (int j = 1; j < i; ++j) {
if (col[j] == -1) dfs(j, 0);
}
std::vector<int> X, Y;
for (int j = 1; j < i; ++j) {
if (col[j] == 0) X.push_back(j);
else Y.push_back(j);
}
for (int j = 0; j < 2; ++j) {
while (!check(X, i)) {
int left = 1, right = X.size();
while (left < right) {
int mid = (left + right - 1) >> 1;
if (!check({X.begin(), X.begin() + mid}, i)) right = mid;
else left = mid + 1;
}
edges[i].push_back(X[left - 1]);
edges[X[left - 1]].push_back(i);
X = {X.begin() + left, X.end()};
}
X.swap(Y);
}
}
std::vector<int> mate(N * 2 + 1, -1);
std::vector<int> love(N * 2 + 1, -1), loved(N * 2 + 1, -1);
for (int i = 1; i <= N * 2; ++i) {
if (edges[i].size() == 3) {
int u1 = edges[i][0], u2 = edges[i][1], u3 = edges[i][2];
int v = -1;
if (Query({u1, u2, i}) == 1) v = u3;
if (Query({u2, u3, i}) == 1) v = u1;
if (Query({u3, u1, i}) == 1) v = u2;
love[i] = v; loved[v] = i;
} else {
mate[i] = edges[i][0];
}
}
for (int i = 1; i <= N * 2; ++i) if (edges[i].size() == 3) {
assert(love[i] != -1 && loved[i] != -1);
for (auto &x: edges[i]) {
if (x != love[i] && x != loved[i]) mate[i] = x;
}
}
for (int i = 1; i <= N * 2; ++i) {
if (i < mate[i]) Answer(i, mate[i]);
}
}
Compilation message
chameleon.cpp: In function 'bool check(std::vector<int>, int)':
chameleon.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
return Query(v) == v.size();
~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
308 KB |
Output is correct |
3 |
Correct |
36 ms |
432 KB |
Output is correct |
4 |
Correct |
37 ms |
384 KB |
Output is correct |
5 |
Correct |
36 ms |
384 KB |
Output is correct |
6 |
Correct |
36 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
40 ms |
504 KB |
Output is correct |
9 |
Correct |
36 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 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 |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
5 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
57 ms |
416 KB |
Output is correct |
4 |
Correct |
64 ms |
384 KB |
Output is correct |
5 |
Correct |
57 ms |
384 KB |
Output is correct |
6 |
Correct |
58 ms |
384 KB |
Output is correct |
7 |
Correct |
58 ms |
384 KB |
Output is correct |
8 |
Correct |
58 ms |
384 KB |
Output is correct |
9 |
Correct |
58 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
308 KB |
Output is correct |
3 |
Correct |
36 ms |
432 KB |
Output is correct |
4 |
Correct |
37 ms |
384 KB |
Output is correct |
5 |
Correct |
36 ms |
384 KB |
Output is correct |
6 |
Correct |
36 ms |
384 KB |
Output is correct |
7 |
Correct |
36 ms |
384 KB |
Output is correct |
8 |
Correct |
40 ms |
504 KB |
Output is correct |
9 |
Correct |
36 ms |
384 KB |
Output is correct |
10 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 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 |
6 ms |
384 KB |
Output is correct |
21 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
57 ms |
416 KB |
Output is correct |
31 |
Correct |
64 ms |
384 KB |
Output is correct |
32 |
Correct |
57 ms |
384 KB |
Output is correct |
33 |
Correct |
58 ms |
384 KB |
Output is correct |
34 |
Correct |
58 ms |
384 KB |
Output is correct |
35 |
Correct |
58 ms |
384 KB |
Output is correct |
36 |
Correct |
58 ms |
384 KB |
Output is correct |
37 |
Correct |
58 ms |
384 KB |
Output is correct |
38 |
Correct |
37 ms |
448 KB |
Output is correct |
39 |
Correct |
58 ms |
384 KB |
Output is correct |
40 |
Correct |
58 ms |
384 KB |
Output is correct |
41 |
Correct |
58 ms |
384 KB |
Output is correct |
42 |
Correct |
36 ms |
384 KB |
Output is correct |
43 |
Correct |
58 ms |
384 KB |
Output is correct |
44 |
Correct |
58 ms |
384 KB |
Output is correct |
45 |
Correct |
58 ms |
384 KB |
Output is correct |