#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> nxt, chk;
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);
A = x[A+1], B = x[B+1], C = x[C+1];
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);
v[A].push_back(u), v[B].push_back(u), v[C].push_back(u);
}
void solve2(const vector<int> &g, const vector<int> &b){
for(int u : b){
find(u, g);
if(v[u].size() == 1){
chk[u] = chk[v[u][0]] = 1, Answer(u, v[u][0]);
}
}
for(int u : g) if(!chk[u]){
if(v[u].size() == 1){
chk[u] = chk[v[u][0]] = 1, Answer(u, v[u][0]);
continue;
}
int A = v[u][0], B = v[u][1], C = v[u][2];
if(Query({u, B, C}) == 1){
swap(A, C);
}else if(Query({u, A, C}) == 1){
swap(B, C);
}
nxt[u] = C;
}
for(int i : b) if(!chk[i]){
int x = (v[i].size() == 1 || chk[v[i][1]] || nxt[v[i][1]] == i ? v[i][0] : v[i][1]);
chk[i] = chk[x] = 1, Answer(i, x);
}
}
void Solve(int N) {
nxt.resize(2*N+1), v.resize(2*N+1), chk.resize(2*N+1);
vector<int> g, b;
if(N <= 50){
vector<int> v[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) v[i].push_back(j), v[j].push_back(i);
vector<int> chk2(2*N+1);
for(int i=1;i<=2*N;i++) if(!chk[i]){
queue<pair<int, int>> q; chk2[i] = 1, q.push({i, 0});
while(!q.empty()){
auto [u, c] = q.front(); q.pop();
(c ? b : g).push_back(u);
for(auto x : v[u]) if(!chk2[x]) chk2[x] = 1, q.push({x, !c});
}
solve2(g, b);
b.clear(), g.clear();
}
}else{
for(int i=1;i<=N;i++) b.push_back(i), g.push_back(N+i);
solve2(g, b);
}
}
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;
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Runtime error |
28 ms |
488 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
200 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 |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
45 ms |
348 KB |
Output is correct |
4 |
Correct |
45 ms |
372 KB |
Output is correct |
5 |
Correct |
37 ms |
368 KB |
Output is correct |
6 |
Correct |
37 ms |
328 KB |
Output is correct |
7 |
Correct |
38 ms |
364 KB |
Output is correct |
8 |
Correct |
40 ms |
356 KB |
Output is correct |
9 |
Correct |
44 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Runtime error |
28 ms |
488 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |