#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define pb push_back
const int MN = 1005;
vi g[4], adj[MN], acc; int i, j, k, lo, hi, vs[MN], ord[MN], c, p[MN], ans[MN], lst;
set<int> ed[MN];
mt19937 mt(time(0));
int Query(const vi &vec);
void Answer(int a,int b);
void dfs(int n,int par){
if(vs[n]) return;
vs[n] = 1;
lst = n;
int pid = 0;
for(int i=0;i<adj[n].size();i++){
if(adj[n][i]==par){
pid = i;
break;
}
}
int ot = (pid+1)%3;
vi tmp;
tmp.pb(n);
tmp.pb(par);
tmp.pb(adj[n][ot]);
if(Query(tmp)!=1) ot=3-pid-ot;
if(!ans[adj[n][ot]]){
Answer(n,adj[n][ot]);
ans[n]=ans[adj[n][ot]]=1;
}
dfs(adj[n][3-pid-ot],n);
}
void Solve(int N){
N *= 2;
for(i=1;i<=N;i++)
ord[i] = i;
shuffle(ord+1,ord+N+1,mt);
for(i=1;i<=N;i++){
int fs = 3;
for(j=0;j<4;j++){
if(g[j].empty()){
fs=min(fs,j);
continue;
}
acc.clear();
acc.insert(acc.end(),g[j].begin(),g[j].end());
acc.pb(ord[i]);
if(Query(acc)!=acc.size()){
while(1){
for(auto v : g[j])
if(!ed[ord[i]].count(v)) hi++;
lo=0; hi--;
while(lo<hi){
int m = (lo+hi)>>1;
acc.clear(); acc.pb(ord[i]);
for(k=c=0;k<g[j].size()&&c<=m;k++){
if(!ed[ord[i]].count(g[j][k])) acc.pb(g[j][k]), c++;
}
if(Query(acc)==acc.size()) lo=m+1;
else hi=m;
}
for(k=c=0;k<g[j].size()&&c<=lo;k++)
if(!ed[ord[i]].count(g[j][k])) c++;
adj[g[j][k-1]].pb(ord[i]);
adj[ord[i]].pb(g[j][k-1]);
ed[g[j][k-1]].insert(ord[i]);
ed[ord[i]].insert(g[j][k-1]);
acc.clear();
for(auto v : g[j])
if(!ed[ord[i]].count(v)) acc.pb(v);
if(acc.empty()) break;
acc.pb(ord[i]);
if(Query(acc)==acc.size()) break;
}
}
else fs=min(fs,j);
}
g[fs].pb(ord[i]);
}
for(i=1;i<=N;i++){
if(vs[i]) continue;
if(ed[i].size()==1){
if(!ans[i]){
Answer(i,adj[i][0]);
ans[i]=ans[adj[i][0]]=1;
}
}
else{
vs[i] = 1;
acc.clear();
acc.pb(i);
acc.pb(adj[i][0]);
acc.pb(adj[i][1]);
if(Query(acc)==1){
dfs(adj[i][2], i);
int sm = 2;
for(j=0;j<adj[i].size();j++)
if(adj[i][j]==lst) sm+=j;
if(!ans[i]){
Answer(i,adj[i][3-sm]);
ans[i]=ans[adj[i][3-sm]]=1;
}
continue;
}
acc.clear();
acc.pb(i);
acc.pb(adj[i][0]);
acc.pb(adj[i][2]);
int sm = 0;
if(Query(acc)==1) sm = 1;
else sm = 0;
dfs(adj[i][sm], i);
for(j=0;j<adj[i].size();j++)
if(adj[i][j]==lst) sm+=j;
if(!ans[i]){
Answer(i,adj[i][3-sm]);
ans[i]=ans[adj[i][3-sm]]=1;
}
}
}
}
Compilation message
chameleon.cpp: In function 'void dfs(int, int)':
chameleon.cpp:21:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[n].size();i++){
~^~~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:55:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(acc)!=acc.size()){
~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:63:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=c=0;k<g[j].size()&&c<=m;k++){
~^~~~~~~~~~~~
chameleon.cpp:66:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(acc)==acc.size()) lo=m+1;
~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:69:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(k=c=0;k<g[j].size()&&c<=lo;k++)
~^~~~~~~~~~~~
chameleon.cpp:80:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(acc)==acc.size()) break;
~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:104:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<adj[i].size();j++)
~^~~~~~~~~~~~~~
chameleon.cpp:120:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<adj[i].size();j++)
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
42 ms |
512 KB |
Output is correct |
4 |
Correct |
41 ms |
512 KB |
Output is correct |
5 |
Correct |
41 ms |
512 KB |
Output is correct |
6 |
Correct |
41 ms |
512 KB |
Output is correct |
7 |
Correct |
41 ms |
512 KB |
Output is correct |
8 |
Correct |
41 ms |
512 KB |
Output is correct |
9 |
Correct |
41 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
5 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 |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
5 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 |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
560 KB |
Output is correct |
14 |
Correct |
5 ms |
480 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
81 ms |
632 KB |
Output is correct |
4 |
Correct |
81 ms |
672 KB |
Output is correct |
5 |
Correct |
92 ms |
636 KB |
Output is correct |
6 |
Correct |
80 ms |
632 KB |
Output is correct |
7 |
Correct |
82 ms |
632 KB |
Output is correct |
8 |
Correct |
82 ms |
632 KB |
Output is correct |
9 |
Correct |
81 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
42 ms |
512 KB |
Output is correct |
4 |
Correct |
41 ms |
512 KB |
Output is correct |
5 |
Correct |
41 ms |
512 KB |
Output is correct |
6 |
Correct |
41 ms |
512 KB |
Output is correct |
7 |
Correct |
41 ms |
512 KB |
Output is correct |
8 |
Correct |
41 ms |
512 KB |
Output is correct |
9 |
Correct |
41 ms |
512 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 |
5 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 |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
560 KB |
Output is correct |
23 |
Correct |
5 ms |
480 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 |
5 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
81 ms |
632 KB |
Output is correct |
31 |
Correct |
81 ms |
672 KB |
Output is correct |
32 |
Correct |
92 ms |
636 KB |
Output is correct |
33 |
Correct |
80 ms |
632 KB |
Output is correct |
34 |
Correct |
82 ms |
632 KB |
Output is correct |
35 |
Correct |
82 ms |
632 KB |
Output is correct |
36 |
Correct |
81 ms |
632 KB |
Output is correct |
37 |
Correct |
84 ms |
608 KB |
Output is correct |
38 |
Correct |
41 ms |
512 KB |
Output is correct |
39 |
Correct |
82 ms |
760 KB |
Output is correct |
40 |
Correct |
84 ms |
632 KB |
Output is correct |
41 |
Correct |
83 ms |
632 KB |
Output is correct |
42 |
Correct |
41 ms |
512 KB |
Output is correct |
43 |
Correct |
88 ms |
936 KB |
Output is correct |
44 |
Correct |
81 ms |
632 KB |
Output is correct |
45 |
Correct |
85 ms |
632 KB |
Output is correct |