This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "chameleon.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
namespace {
int query(vector<int> v){
for(int &x: v) x++;
return Query(v);
}
void answer(int a, int b){
Answer(a+1, b+1);
}
int n;
vector<vector<int>> v;
set<pair<int, int>> s;
vector<int> g[2];
vector<int> color;
void dfs(int nd, int c){
color[nd] = c;
g[c].pb(nd);
c = 1-c;
for(int x: v[nd]){
if(color[x] == c) continue;
else dfs(x, c);
}
}
void make_groups(int m){
color.assign(m+1, -1);
g[0].clear();
g[1].clear();
for(int i = 0; i <= m; i++) if(color[i] == -1) dfs(i, 0);
}
void bs(int i, vector<int> sth){
while(!sth.empty()){
auto ss = sth;
ss.pb(i);
if(query(ss) == ss.size()) break;
int l = 0, r = sth.size();
while(l < r){
int md = (l+r)/2;
vector<int> ss(sth.begin(), sth.begin()+md+1);
ss.pb(i);
if(query(ss) == ss.size()) l = md+1;
else r = md;
}
v[i].pb(sth[l]);
v[sth[l]].pb(i);
sth.erase(sth.begin()+l);
}
}
}
void Solve(int _n){
n = _n;
v.resize(2*n);
for(int i = 0; i < 2*n; i++){
bs(i, g[0]);
bs(i, g[1]);
make_groups(i);
}
for(int i = 0; i < 2*n; i++) for(int x: v[i]) s.insert({min(i, x), max(i, x)});
for(int i = 0; i < 2*n; i++){
if(v[i].size() < 3) continue;
int a = v[i][0], b = v[i][1], c = v[i][2];
int rm = -1;
if(query({i, a, b}) == 1) rm = c;
else if(query({i, a, c}) == 1) rm = b;
else rm = a;
if(s.find({min(i, rm), max(i, rm)}) != s.end()) s.erase({min(i, rm), max(i, rm)});
}
for(auto [a, b]: s) answer(a, b);
}
Compilation message (stderr)
chameleon.cpp: In function 'void {anonymous}::bs(int, std::vector<int>)':
chameleon.cpp:46:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(query(ss) == ss.size()) break;
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | if(query(ss) == ss.size()) l = md+1;
| ~~~~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |