#include <bits/stdc++.h>
using namespace std;
int Query(const std::vector<int> &p);
void Answer(int a, int b);
void Solve(int N) {
int n = N;
vector<vector<int>> adj(2*n+1);
set<pair<int,int>> edges;
vector<vector<int>> sets;
for(int i=1;i<=2*n;i++){
// Find all edges which correspond to
sets = vector<vector<int>>(2);
vector<bool> visited(2*n+1);
function<void(int,int)> dfs = [&](int x,int col){
if(visited[x])return;
visited[x]=true;
sets[col].emplace_back(x);
for(int&i:adj[x])dfs(i,(col+1)%2);
};
for(int j=1;j<i;j++)dfs(j,0);
for(int arr=0;arr<2;arr++){
vector<int> msuspects=sets[arr];
sort(msuspects.begin(),msuspects.end());
while(true){
auto base = msuspects.size();
msuspects.emplace_back(i);
if(Query(msuspects)>base)break;
msuspects.erase(--msuspects.end());
auto suspects = msuspects;
while(suspects.size()>1){
int mid = suspects.size()/2;
vector<int> left,right;
for(int i=0;i<mid;i++)left.emplace_back(suspects[i]);
for(int i=mid;i<suspects.size();i++)right.emplace_back(suspects[i]);
auto b = left.size();
left.emplace_back(i);
if(Query(left)>b)suspects=right;
else {
left.erase(--left.end());
suspects = left;
}
}
msuspects.erase(lower_bound(msuspects.begin(),msuspects.end(),suspects[0]));
edges.insert({min(i,suspects[0]),max(i,suspects[0])});
adj[i].emplace_back(suspects[0]);
adj[suspects[0]].emplace_back(i);
}
}
}
for(int i=1;i<=2*n;i++){
if(adj[i].size()==1)continue;
assert(adj[i].size()==3);
if(Query({i,adj[i][0],adj[i][1]})==1)edges.erase({min(i,adj[i][2]),max(i,adj[i][2])});
else if(Query({i,adj[i][0],adj[i][2]})==1)edges.erase({min(i,adj[i][1]),max(i,adj[i][1])});
else edges.erase({min(i,adj[i][0]),max(i,adj[i][0])});
}
for(auto[a,b]:edges)Answer(a,b);
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:29:33: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
29 | if(Query(msuspects)>base)break;
| ~~~~~~~~~~~~~~~~^~~~~
chameleon.cpp:36:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i=mid;i<suspects.size();i++)right.emplace_back(suspects[i]);
| ~^~~~~~~~~~~~~~~~
chameleon.cpp:39:32: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
39 | if(Query(left)>b)suspects=right;
| ~~~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
21 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
344 KB |
Output is correct |
5 |
Correct |
21 ms |
344 KB |
Output is correct |
6 |
Correct |
21 ms |
528 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
52 ms |
644 KB |
Output is correct |
4 |
Correct |
45 ms |
600 KB |
Output is correct |
5 |
Correct |
47 ms |
616 KB |
Output is correct |
6 |
Correct |
46 ms |
600 KB |
Output is correct |
7 |
Correct |
45 ms |
600 KB |
Output is correct |
8 |
Correct |
45 ms |
652 KB |
Output is correct |
9 |
Correct |
58 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
21 ms |
344 KB |
Output is correct |
4 |
Correct |
21 ms |
344 KB |
Output is correct |
5 |
Correct |
21 ms |
344 KB |
Output is correct |
6 |
Correct |
21 ms |
528 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 |
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 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
52 ms |
644 KB |
Output is correct |
31 |
Correct |
45 ms |
600 KB |
Output is correct |
32 |
Correct |
47 ms |
616 KB |
Output is correct |
33 |
Correct |
46 ms |
600 KB |
Output is correct |
34 |
Correct |
45 ms |
600 KB |
Output is correct |
35 |
Correct |
45 ms |
652 KB |
Output is correct |
36 |
Correct |
58 ms |
556 KB |
Output is correct |
37 |
Correct |
46 ms |
596 KB |
Output is correct |
38 |
Correct |
21 ms |
344 KB |
Output is correct |
39 |
Correct |
46 ms |
620 KB |
Output is correct |
40 |
Correct |
48 ms |
584 KB |
Output is correct |
41 |
Correct |
51 ms |
564 KB |
Output is correct |
42 |
Correct |
22 ms |
344 KB |
Output is correct |
43 |
Correct |
52 ms |
644 KB |
Output is correct |
44 |
Correct |
46 ms |
600 KB |
Output is correct |
45 |
Correct |
50 ms |
580 KB |
Output is correct |