#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> b, g, nxt;
vector<vector<int>> v;
int lb(int u, const vector<int> &x, int l){
int L = l, R = x.size()-1;
while(L <= R){
int M = (L+R)/2;
vector<int> Q(1, u);
for(int i=l;i<=M;i++) Q.push_back(x[i]);
if(Query(Q) == Q.size()) L = M+1;
else R = M-1;
}
return L == x.size() ? -2 : R;
}
void find(int u, const vector<int> &x){
int A = lb(u, x, 0);
int B = lb(u, x, A+2);
if(B < -1){
v[u].push_back(x[A+1]);
return;
}
int C = lb(u, x, B+2);
// cout << A << " " << B << " " << C << "\n";
A = x[A+1], B = x[B+1], C = x[C+1];
// cout << A << " " << B << " " << C << "\n";
if(Query({u, B, C}) == 1){
swap(A, C);
}else if(Query({u, A, C}) == 1){
swap(B, C);
}
nxt[u] = C;
v[u].push_back(A), v[u].push_back(B);
}
void Solve(int N) {
nxt.resize(2*N+1), v.resize(2*N+1);
if(N <= 50){
vector<int> v2[2*N+1];
for(int i=1;i<=2*N;i++) for(int j=i+1;j<=2*N;j++) if(Query({i, j}) == 1) v2[i].push_back(j), v2[j].push_back(i);
vector<bool> chk(2*N+1), chk2(2*N+1);
for(int i=1;i<=2*N;i++) if(!chk[i]){
vector<int> nodes;
queue<pair<int, int>> q; chk[i] = 1, q.push({i, 0});
while(!q.empty()){
auto [u, c] = q.front(); q.pop();
nodes.push_back(u);
(c ? b : g).push_back(u);
for(auto x : v2[u]) if(!chk[x]) chk[x] = 1, q.push({x, !c});
}
for(int u : b) find(u, g);
for(int u : g) find(u, b);
for(int i : nodes) if(!chk2[i]) {
int x = (v[i].size() == 1 || chk2[v[i][1]] || nxt[v[i][1]] == i ? v[i][0] : v[i][1]);
chk2[i] = chk2[x] = 1, Answer(i, x);
}
b.clear(), g.clear();
}
}else{
vector<bool> chk(2*N+1);
for(int i=1;i<=2*N;i++) if(!chk[i]){
vector<int> Q;
for(int j=1;j<=2*N;j++) if(!chk[j]) Q.push_back(j);
find(i, Q);
chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]);
}
}
}
Compilation message
chameleon.cpp: In function 'int lb(int, const std::vector<int>&, int)':
chameleon.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(Query(Q) == Q.size()) L = M+1;
| ~~~~~~~~~^~~~~~~~~~~
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 | return L == x.size() ? -2 : R;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [2] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
2 ms |
200 KB |
Output is correct |
11 |
Correct |
2 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
200 KB |
Output is correct |
16 |
Correct |
2 ms |
200 KB |
Output is correct |
17 |
Correct |
3 ms |
200 KB |
Output is correct |
18 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [2] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [2] |
4 |
Halted |
0 ms |
0 KB |
- |