#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
int p[1005];
int inv[1005];
vector<int> adjl[1005];
void func(int num, vector<int> opts){
if (opts.size()==1){
adjl[num].push_back(opts[0]);
adjl[opts[0]].push_back(num);
return;
}
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]);
}
}
lhalf.push_back(num);
int res = Query(lhalf);
if (res!=lhalf.size()){
lhalf.pop_back();
func(num,lhalf);
}
rhalf.push_back(num);
res = Query(rhalf);
if (res!=rhalf.size()){
rhalf.pop_back();
func(num,rhalf);
}
}
}
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++){
func(x,opt);
}
}
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 'void {anonymous}::func(int, std::vector<int>)':
chameleon.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int x = 0; x<opts.size(); x++){
| ~^~~~~~~~~~~~
chameleon.cpp:20:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (x<opts.size()/2){
| ~^~~~~~~~~~~~~~
chameleon.cpp:29:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if (res!=lhalf.size()){
| ~~~^~~~~~~~~~~~~~
chameleon.cpp:35:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (res!=rhalf.size()){
| ~~~^~~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:68:17: warning: unused variable 'res3' [-Wunused-variable]
68 | int res3 = Query({x,adjl[x][0],adjl[x][2]});
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
61 ms |
328 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
2 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Incorrect |
58 ms |
360 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
61 ms |
328 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |