#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int p[1005];
int inv[1005];
vector<int> adjl[1005];
int func(int num, vector<int> opts, int lim){
// printf("%d??\n",opts.size());
if (opts.size()==1){
adjl[num].push_back(opts[0]);
adjl[opts[0]].push_back(num);
return 1;
}
// random_shuffle(opts.begin(),opts.end()); ///not needed?
vector<int> lhalf, rhalf;
for (int x = 0; x<opts.size(); x++){
if (x<opts.size()/2){
lhalf.push_back(opts[x]);
}
else{
rhalf.push_back(opts[x]);
}
}
int t = 0;
lhalf.push_back(num);
int res = Query(lhalf);
if (res!=lhalf.size()){
lhalf.pop_back();
t += func(num,lhalf,lim);
}
if (t>=lim) return t;
rhalf.push_back(num);
if (rhalf.size()!=2){
rhalf.pop_back();
t+= func(num,rhalf,lim-t);
}
else if ( Query(rhalf)!=rhalf.size()){
// printf("queried twice\n");
rhalf.pop_back();
t+= func(num,rhalf,lim-t);
}
return t;
}
}
void Solve(int N) {
if (N<=50){
for (int x = 1; x<=2*N; x++){
for (int y = x+1; y<=2*N; y++){
int res = Query({x,y});
if (res==1){
adjl[x].push_back(y);
adjl[y].push_back(x);
}
}
}
}
else{
vector<int> opt;
for (int x = N+1; x<=2*N; x++){
opt.push_back(x);
}
for (int x = 1; x<=N; x++){
//int num = query_count;
func(x,opt,1);
vector<int> opt2;
for (int y = adjl[x][0]+1; y<=2*N; y++){
opt2.push_back(y);
}
if (opt2.size()>1){
int res = func(x,opt2,1);
opt2.clear();
if (res==1 ){
for (int y = adjl[x][1]+1; y<=2*N; y++){
opt2.push_back(y);
}
if (opt2.size()>1){
func(x,opt2,1);
}
else if (opt2.size()==1){
adjl[x].push_back(opt2[0]);
adjl[opt2[0]].push_back(x);
}
}
}
// printf("queries taken %d\n",query_count-num);
}
}
// printf("cur query count = %d\n",query_count);
for (int x = 1; x<=2*N; x++){
if (adjl[x].size()==3){
int res1 = Query({x,adjl[x][0],adjl[x][1]});
int res2 = Query({x,adjl[x][1],adjl[x][2]});
int res3 = Query({x,adjl[x][0],adjl[x][2]});
if (res1==1){
p[x] = adjl[x][2];
}
else if (res2==1){
p[x] = adjl[x][0];
}
else{
p[x] = adjl[x][1];
}
inv[p[x]] = x;
}
}
for (int x = 1; x<=2*N; x++){
if (adjl[x].size()<3){
if (x<adjl[x][0]){
Answer(x,adjl[x][0]);
}
}
else{
int other = -1;
for (auto y : adjl[x]){
if (y==p[x]) continue;
if (y==inv[x]) continue;
other = y;
}
if (x<other){
Answer(x,other);
}
}
}
}
Compilation message
chameleon.cpp: In function 'int {anonymous}::func(int, std::vector<int>, int)':
chameleon.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int x = 0; x<opts.size(); x++){
| ~^~~~~~~~~~~~
chameleon.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (x<opts.size()/2){
| ~^~~~~~~~~~~~~~
chameleon.cpp:31:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if (res!=lhalf.size()){
| ~~~^~~~~~~~~~~~~~
chameleon.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | else if ( Query(rhalf)!=rhalf.size()){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:99:17: warning: unused variable 'res3' [-Wunused-variable]
99 | int res3 = Query({x,adjl[x][0],adjl[x][2]});
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Runtime error |
2 ms |
456 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
2 ms |
328 KB |
Output is correct |
12 |
Correct |
3 ms |
328 KB |
Output is correct |
13 |
Correct |
2 ms |
328 KB |
Output is correct |
14 |
Correct |
2 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
328 KB |
Output is correct |
16 |
Correct |
2 ms |
328 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
41 ms |
384 KB |
Output is correct |
4 |
Correct |
36 ms |
392 KB |
Output is correct |
5 |
Correct |
36 ms |
404 KB |
Output is correct |
6 |
Correct |
36 ms |
400 KB |
Output is correct |
7 |
Correct |
40 ms |
380 KB |
Output is correct |
8 |
Correct |
38 ms |
448 KB |
Output is correct |
9 |
Correct |
36 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Runtime error |
2 ms |
456 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |