#include "chameleon.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
namespace {
int query(vector<int> v){
for(int &x: v) x++;
return Query(v);
}
void answer(int a, int b){
Answer(a+1, b+1);
}
int n;
vector<vector<int>> v;
set<pair<int, int>> s;
vector<int> g[2];
vector<int> color;
void dfs(int nd, int c){
color[nd] = c;
g[c].pb(nd);
c = 1-c;
for(int x: v[nd]){
if(color[x] == c) continue;
else dfs(x, c);
}
}
void make_groups(int m){
color.assign(m+1, -1);
g[0].clear();
g[1].clear();
for(int i = 0; i <= m; i++) if(color[i] == -1) dfs(i, 0);
}
void bs(int i, vector<int> sth){
while(!sth.empty()){
auto ss = sth;
ss.pb(i);
if(query(ss) == ss.size()) break;
int l = 0, r = sth.size();
while(l < r){
int md = (l+r)/2;
vector<int> ss(sth.begin(), sth.begin()+md+1);
ss.pb(i);
if(query(ss) == ss.size()) l = md+1;
else r = md;
}
v[i].pb(sth[l]);
v[sth[l]].pb(i);
sth.erase(sth.begin()+l);
}
}
}
void Solve(int _n){
n = _n;
v.resize(2*n);
for(int i = 0; i < 2*n; i++){
bs(i, g[0]);
bs(i, g[1]);
make_groups(i);
}
for(int i = 0; i < 2*n; i++) for(int x: v[i]) s.insert({min(i, x), max(i, x)});
for(int i = 0; i < 2*n; i++){
if(v[i].size() < 3) continue;
int a = v[i][0], b = v[i][1], c = v[i][2];
int rm = -1;
if(query({i, a, b}) == 1) rm = c;
else if(query({i, a, c}) == 1) rm = b;
else rm = a;
if(s.find({min(i, rm), max(i, rm)}) != s.end()) s.erase({min(i, rm), max(i, rm)});
}
for(auto [a, b]: s) answer(a, b);
}
Compilation message
chameleon.cpp: In function 'void {anonymous}::bs(int, std::vector<int>)':
chameleon.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(query(ss) == ss.size()) break;
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if(query(ss) == ss.size()) l = md+1;
| ~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
28 ms |
464 KB |
Output is correct |
4 |
Correct |
28 ms |
452 KB |
Output is correct |
5 |
Correct |
30 ms |
468 KB |
Output is correct |
6 |
Correct |
29 ms |
464 KB |
Output is correct |
7 |
Correct |
29 ms |
464 KB |
Output is correct |
8 |
Correct |
28 ms |
468 KB |
Output is correct |
9 |
Correct |
28 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
75 ms |
504 KB |
Output is correct |
4 |
Correct |
73 ms |
504 KB |
Output is correct |
5 |
Correct |
73 ms |
512 KB |
Output is correct |
6 |
Correct |
74 ms |
720 KB |
Output is correct |
7 |
Correct |
75 ms |
572 KB |
Output is correct |
8 |
Correct |
75 ms |
628 KB |
Output is correct |
9 |
Correct |
76 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
28 ms |
464 KB |
Output is correct |
4 |
Correct |
28 ms |
452 KB |
Output is correct |
5 |
Correct |
30 ms |
468 KB |
Output is correct |
6 |
Correct |
29 ms |
464 KB |
Output is correct |
7 |
Correct |
29 ms |
464 KB |
Output is correct |
8 |
Correct |
28 ms |
468 KB |
Output is correct |
9 |
Correct |
28 ms |
476 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
0 ms |
208 KB |
Output is correct |
29 |
Correct |
0 ms |
208 KB |
Output is correct |
30 |
Correct |
75 ms |
504 KB |
Output is correct |
31 |
Correct |
73 ms |
504 KB |
Output is correct |
32 |
Correct |
73 ms |
512 KB |
Output is correct |
33 |
Correct |
74 ms |
720 KB |
Output is correct |
34 |
Correct |
75 ms |
572 KB |
Output is correct |
35 |
Correct |
75 ms |
628 KB |
Output is correct |
36 |
Correct |
76 ms |
468 KB |
Output is correct |
37 |
Correct |
67 ms |
456 KB |
Output is correct |
38 |
Correct |
29 ms |
464 KB |
Output is correct |
39 |
Correct |
69 ms |
556 KB |
Output is correct |
40 |
Correct |
69 ms |
504 KB |
Output is correct |
41 |
Correct |
68 ms |
488 KB |
Output is correct |
42 |
Correct |
28 ms |
464 KB |
Output is correct |
43 |
Correct |
73 ms |
508 KB |
Output is correct |
44 |
Correct |
67 ms |
464 KB |
Output is correct |
45 |
Correct |
69 ms |
568 KB |
Output is correct |