#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
int nxt[1010];
bool chk[1010];
vector<int> v[1010];
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() ? -1 : R;
}
void addEdge(int a, int b){
v[a].push_back(b), v[b].push_back(a);
}
void find(int u, const vector<int> &x){
int A = lb(u, x, 1);
int B = lb(u, x, A+2);
if(B < 0){
addEdge(u, x[A+1]);
return;
}
int C = lb(u, x, B+2);
A = x[A+1], B = x[B+1], C = x[C+1];
addEdge(u, A), addEdge(u, B), addEdge(u, C);
}
void Solve(int N) {
set<int> s; s.insert(1);
for(int i=2;i<=2*N;i++){
s.insert(i);
vector<int> q(s.begin(), s.end());
if(Query(q) != q.size()){
reverse(q.begin(), q.end());
find(i, q);
if(v[i].size() == 3){
s.erase(i);
}else{
for(auto x : v[i]) s.erase(x);
}
}
}
for(int i=1;i<=2*N;i++) if(!chk[i] && v[i].size() < 3){
// int x = i+1;
// while(inside(i, x, 2*N)) v[i].push_back(find_next(i, x, 2*N)), v[v[i].back()].push_back(i), x = v[i].back()+1;
if(v[i].size() == 1) chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]);
}
for(int i=1;i<=2*N;i++) if(!chk[i]){
int &A = v[i][0], &B = v[i][1], &C = v[i][2];
if(Query({i, B, C}) == 1) swap(A, C);
else if(Query({i, A, C}) == 1) swap(B, C);
nxt[i] = C, v[i].pop_back();
}
for(int i=1;i<=2*N;i++) if(!chk[i]){
int x = (chk[v[i][1]] || nxt[v[i][1]] == i ? v[i][0] : v[i][1]);
chk[i] = chk[x] = 1, Answer(i, x);
}
}
Compilation message
chameleon.cpp: In function 'int lb(int, const std::vector<int>&, int)':
chameleon.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(Query(Q) == Q.size()) L = M+1;
| ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | return L == x.size() ? -1 : R;
| ~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if(Query(q) != q.size()){
| ~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
44 ms |
404 KB |
Output is correct |
4 |
Correct |
45 ms |
328 KB |
Output is correct |
5 |
Correct |
46 ms |
392 KB |
Output is correct |
6 |
Correct |
43 ms |
400 KB |
Output is correct |
7 |
Correct |
56 ms |
400 KB |
Output is correct |
8 |
Correct |
44 ms |
408 KB |
Output is correct |
9 |
Correct |
44 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Incorrect |
52 ms |
448 KB |
Wrong Answer [2] |
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 |
Correct |
44 ms |
404 KB |
Output is correct |
4 |
Correct |
45 ms |
328 KB |
Output is correct |
5 |
Correct |
46 ms |
392 KB |
Output is correct |
6 |
Correct |
43 ms |
400 KB |
Output is correct |
7 |
Correct |
56 ms |
400 KB |
Output is correct |
8 |
Correct |
44 ms |
408 KB |
Output is correct |
9 |
Correct |
44 ms |
416 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Incorrect |
0 ms |
328 KB |
Wrong Answer [6] |
12 |
Halted |
0 ms |
0 KB |
- |