#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>>S(4), B(1005), adjs(1005);
vector<bool>vis(1005, 0);
int y;
void ans(int a, int b){
if(vis[a]||vis[b])return;
Answer(a, b);
vis[a]=1, vis[b]=1;
return;
}
vector<int>v;
bool BS(int x){
if(Query(v)==v.size())return 0;
int l=0, r=v.size()-2, ans=-1;
while(r>=l){
int m=(l+r)/2;
vector<int>v1={x};
for(int i=l; i<=m; i++){
v1.push_back(v[i]);
}
if(Query(v1)!=v1.size()){
ans=m;
r=m-1;
}else{
l=m+1;
}
}
adjs[v[ans]].push_back(x);
adjs[x].push_back(v[ans]);
v.erase(v.begin()+ans);
BS(x);
return 1;
}
void Solve(int n) {
n*=2;
y=n;
for(int i=1; i<=n; i++){
vector<bool>X(4, 0);
for(int j=0; j<4; j++){
if(adjs[i].size()==3)break;
if(S[j].size()==0)continue;
v=S[j];
v.push_back(i);
if(BS(i)){
X[j]=1;
}
}
for(int j=0; j<4; j++){
if(!X[j]){
S[j].push_back(i);
break;
}
}
}
for(int i=1; i<=n; i++){
if(adjs[i].size()==1){
ans(i, adjs[i][0]);
}else{
for(int j=0; j<3; j++){
if(j==2){
B[i].push_back(adjs[i][j]);
B[adjs[i][j]].push_back(i);
break;
}
vector<int>A={i};
for(int a=0;a<=2; a++){
if(a!=j)A.push_back(adjs[i][a]);
}
if(Query(A)==1){
B[i].push_back(adjs[i][j]);
B[adjs[i][j]].push_back(i);
break;
}
}
}
}
for(int i=1; i<=n; i++){
if(vis[i])continue;
for(int a:adjs[i]){
if(a!=B[i][0]&&a!=B[i][1]){
ans(i, a);
}
}
}
}
Compilation message
chameleon.cpp: In function 'bool BS(int)':
chameleon.cpp:15:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(v)==v.size())return 0;
~~~~~~~~^~~~~~~~~~
chameleon.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(v1)!=v1.size()){
~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
384 KB |
Output is correct |
4 |
Correct |
21 ms |
384 KB |
Output is correct |
5 |
Correct |
21 ms |
512 KB |
Output is correct |
6 |
Correct |
22 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
512 KB |
Output is correct |
8 |
Correct |
21 ms |
384 KB |
Output is correct |
9 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 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 |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 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 |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
512 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 |
42 ms |
384 KB |
Output is correct |
4 |
Correct |
42 ms |
384 KB |
Output is correct |
5 |
Correct |
42 ms |
384 KB |
Output is correct |
6 |
Correct |
42 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
384 KB |
Output is correct |
8 |
Correct |
42 ms |
504 KB |
Output is correct |
9 |
Correct |
43 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
21 ms |
384 KB |
Output is correct |
4 |
Correct |
21 ms |
384 KB |
Output is correct |
5 |
Correct |
21 ms |
512 KB |
Output is correct |
6 |
Correct |
22 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
512 KB |
Output is correct |
8 |
Correct |
21 ms |
384 KB |
Output is correct |
9 |
Correct |
21 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
512 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 |
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 |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 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 |
42 ms |
384 KB |
Output is correct |
31 |
Correct |
42 ms |
384 KB |
Output is correct |
32 |
Correct |
42 ms |
384 KB |
Output is correct |
33 |
Correct |
42 ms |
384 KB |
Output is correct |
34 |
Correct |
42 ms |
384 KB |
Output is correct |
35 |
Correct |
42 ms |
504 KB |
Output is correct |
36 |
Correct |
43 ms |
384 KB |
Output is correct |
37 |
Correct |
40 ms |
508 KB |
Output is correct |
38 |
Correct |
21 ms |
384 KB |
Output is correct |
39 |
Correct |
37 ms |
384 KB |
Output is correct |
40 |
Correct |
37 ms |
504 KB |
Output is correct |
41 |
Correct |
41 ms |
504 KB |
Output is correct |
42 |
Correct |
22 ms |
384 KB |
Output is correct |
43 |
Correct |
43 ms |
384 KB |
Output is correct |
44 |
Correct |
38 ms |
384 KB |
Output is correct |
45 |
Correct |
38 ms |
384 KB |
Output is correct |