#include "chameleon.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int n;
int bio[MAXN], love[MAXN];
vector <int> v[MAXN], comp[2];
//int Query (vector <int> & p) {}
//void Answer (int a, int b) {}
void dfs (int x, bool col) {
if (bio[x] != -1) return;
bio[x] = col;
comp[col].push_back(x);
for (auto sus : v[x]) {
dfs(sus, !col);
}
}
void split (int m) {
comp[0].clear(); comp[1].clear();
memset(bio, -1, sizeof bio);
for (int i = 1; i <= m; i++) {
if (bio[i] == -1) dfs(i, 0);
}
}
bool ask (int curr, int lo, int hi, vector <int> & c) {
vector <int> q(hi - lo + 1);
for (int i = lo; i <= hi; i++) {
q[i - lo] = c[i];
}
q.push_back(curr);
return Query(q) < q.size();
}
int gen_edge (int curr, vector <int> & c, int lo) {
int hi = (int)c.size() - 1;
if (!ask(curr, lo, hi, c)) return c.size();
while (lo < hi) {
int mid = (lo + hi) / 2;
if (ask(curr, lo, mid, c)) {
hi = mid;
} else {
lo = mid + 1;
}
}
return lo;
}
void build () {
for (int i = 1; i <= 2 * n; i++) {
split(i - 1);
for (int j = 0; j < 2; j++) {
if (comp[j].empty()) continue;
int lo = 0;
while (lo < comp[j].size()) {
int res = gen_edge(i, comp[j], lo);
if (res < comp[j].size()) {
int sus = comp[j][res];
v[sus].push_back(i);
v[i].push_back(sus);
}
lo = res + 1;
}
}
}
}
void Solve (int N) {
n = N;
build();
for (int i = 1; i <= 2 * n; i++) {
if (v[i].size() == 3) {
int a = v[i][0], b = v[i][1], c = v[i][2];
vector <int> q;
q = {i, a, b}; if (Query(q) == 1) love[i] = c;
q = {i, a, c}; if (Query(q) == 1) love[i] = b;
q = {i, b, c}; if (Query(q) == 1) love[i] = a;
}
}
for (int i = 1; i <= 2 * n; i++) {
for (auto sus : v[i]) {
if (love[i] != sus && love[sus] != i && i < sus) Answer(i, sus);
}
}
}
/*int main () {
return 0;
}*/
Compilation message
chameleon.cpp: In function 'bool ask(int, int, int, std::vector<int>&)':
chameleon.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
return Query(q) < q.size();
~~~~~~~~~^~~~~~~~~~
chameleon.cpp: In function 'void build()':
chameleon.cpp:61:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (lo < comp[j].size()) {
~~~^~~~~~~~~~~~~~~~
chameleon.cpp:63:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (res < comp[j].size()) {
~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
27 ms |
384 KB |
Output is correct |
4 |
Correct |
26 ms |
384 KB |
Output is correct |
5 |
Correct |
26 ms |
384 KB |
Output is correct |
6 |
Correct |
26 ms |
384 KB |
Output is correct |
7 |
Correct |
26 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
384 KB |
Output is correct |
9 |
Correct |
26 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 |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
436 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 |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
436 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 |
5 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 |
6 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 |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
50 ms |
504 KB |
Output is correct |
4 |
Correct |
58 ms |
440 KB |
Output is correct |
5 |
Correct |
51 ms |
504 KB |
Output is correct |
6 |
Correct |
52 ms |
384 KB |
Output is correct |
7 |
Correct |
52 ms |
512 KB |
Output is correct |
8 |
Correct |
50 ms |
504 KB |
Output is correct |
9 |
Correct |
59 ms |
504 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 |
27 ms |
384 KB |
Output is correct |
4 |
Correct |
26 ms |
384 KB |
Output is correct |
5 |
Correct |
26 ms |
384 KB |
Output is correct |
6 |
Correct |
26 ms |
384 KB |
Output is correct |
7 |
Correct |
26 ms |
384 KB |
Output is correct |
8 |
Correct |
26 ms |
384 KB |
Output is correct |
9 |
Correct |
26 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
436 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 |
5 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 |
6 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 |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
50 ms |
504 KB |
Output is correct |
31 |
Correct |
58 ms |
440 KB |
Output is correct |
32 |
Correct |
51 ms |
504 KB |
Output is correct |
33 |
Correct |
52 ms |
384 KB |
Output is correct |
34 |
Correct |
52 ms |
512 KB |
Output is correct |
35 |
Correct |
50 ms |
504 KB |
Output is correct |
36 |
Correct |
59 ms |
504 KB |
Output is correct |
37 |
Correct |
52 ms |
488 KB |
Output is correct |
38 |
Correct |
26 ms |
384 KB |
Output is correct |
39 |
Correct |
52 ms |
384 KB |
Output is correct |
40 |
Correct |
59 ms |
512 KB |
Output is correct |
41 |
Correct |
55 ms |
512 KB |
Output is correct |
42 |
Correct |
27 ms |
384 KB |
Output is correct |
43 |
Correct |
50 ms |
504 KB |
Output is correct |
44 |
Correct |
51 ms |
504 KB |
Output is correct |
45 |
Correct |
52 ms |
384 KB |
Output is correct |