#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
int nxt[1010];
bool chk[1010];
vector<int> v[1010];
void addEdge(int a, int b){
v[a].push_back(b), v[b].push_back(a);
}
int find_next(const int u, const vector<int> &q){
if(q.empty() || v[u].size() == 3) return 0;
vector<int> Q2(1, u);
for(auto x : q) Q2.push_back(x);
if(Query(Q2) == Q2.size()) return 0;
int L = 0, R = q.size()-1;
while(L <= R){
int M = (L+R)/2;
vector<int> Q(1, u);
for(int i=0;i<=M;i++) Q.push_back(q[i]);
if(Query(Q) == Q.size()) L = M+1;
else R = M-1;
}
if(L == q.size()) return 0;
addEdge(u, q[R+1]);
return q[R+1];
}
void compress(set<int> &s){
for(auto it = s.begin(); it != s.end(); ){
if(v[*it].size() == 3) it = s.erase(it);
else it = next(it);
}
}
void Solve(int N) {
set<int> s1, s2;
for(int i=1;i<=2*N;i++){
compress(s1), compress(s2);
vector<int> q1(s1.begin(), s1.end()), q2(s2.begin(), s2.end());
int k = 0;
while(k = find_next(i, q1)){
while(!q1.empty() && *q1.begin() <= k) q1.erase(q1.begin());
}
while(k = find_next(i, q2)){
while(!q2.empty() && *q2.begin() <= k) q2.erase(q2.begin());
}
vector<int> chk2(2*N+1), g, b;
queue<pair<int, int>> q; chk2[i] = 1; q.push({i, 0});
while(!q.empty()){
auto [u, c] = q.front(); q.pop();
if(s1.count(u)) s1.erase(u);
if(s2.count(u)) s2.erase(u);
(c ? b : g).push_back(u);
for(auto x : v[u]) if(!chk2[x]) chk2[x] = 1, q.push({x, !c});
}
for(auto x : g) s1.insert(x);
for(auto x : b) s2.insert(x);
}
// for(int i=1;i<=2*N;i++){
// printf("[%d] :",i);
// for(int x : v[i]) printf(" %d",x);
// puts("");
// }
// ---------------------------------------- don't touch line -----------------------------------------
for(int i=1;i<=2*N;i++) if(!chk[i])
{if(v[i].size() == 1){
chk[i] = chk[v[i][0]] = 1, Answer(i, v[i][0]);
continue;
}
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 find_next(int, const std::vector<int>&)':
chameleon.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(Query(Q2) == Q2.size()) return 0;
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if(Query(Q) == Q.size()) L = M+1;
| ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:31:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if(L == q.size()) return 0;
| ~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:52:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
52 | while(k = find_next(i, q1)){
| ~~^~~~~~~~~~~~~~~~~~
chameleon.cpp:55:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
55 | while(k = find_next(i, q2)){
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
51 ms |
328 KB |
Output is correct |
4 |
Correct |
50 ms |
328 KB |
Output is correct |
5 |
Correct |
51 ms |
396 KB |
Output is correct |
6 |
Correct |
51 ms |
416 KB |
Output is correct |
7 |
Correct |
51 ms |
396 KB |
Output is correct |
8 |
Correct |
50 ms |
420 KB |
Output is correct |
9 |
Correct |
50 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 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 |
0 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 |
268 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 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 |
0 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 |
268 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
2 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 |
1 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 |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
131 ms |
420 KB |
Output is correct |
4 |
Correct |
131 ms |
408 KB |
Output is correct |
5 |
Correct |
128 ms |
420 KB |
Output is correct |
6 |
Correct |
131 ms |
412 KB |
Output is correct |
7 |
Correct |
132 ms |
656 KB |
Output is correct |
8 |
Correct |
130 ms |
404 KB |
Output is correct |
9 |
Correct |
133 ms |
440 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 |
51 ms |
328 KB |
Output is correct |
4 |
Correct |
50 ms |
328 KB |
Output is correct |
5 |
Correct |
51 ms |
396 KB |
Output is correct |
6 |
Correct |
51 ms |
416 KB |
Output is correct |
7 |
Correct |
51 ms |
396 KB |
Output is correct |
8 |
Correct |
50 ms |
420 KB |
Output is correct |
9 |
Correct |
50 ms |
400 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
0 ms |
328 KB |
Output is correct |
13 |
Correct |
0 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
268 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
2 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
2 ms |
328 KB |
Output is correct |
22 |
Correct |
2 ms |
328 KB |
Output is correct |
23 |
Correct |
2 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
328 KB |
Output is correct |
27 |
Correct |
2 ms |
328 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
0 ms |
328 KB |
Output is correct |
30 |
Correct |
131 ms |
420 KB |
Output is correct |
31 |
Correct |
131 ms |
408 KB |
Output is correct |
32 |
Correct |
128 ms |
420 KB |
Output is correct |
33 |
Correct |
131 ms |
412 KB |
Output is correct |
34 |
Correct |
132 ms |
656 KB |
Output is correct |
35 |
Correct |
130 ms |
404 KB |
Output is correct |
36 |
Correct |
133 ms |
440 KB |
Output is correct |
37 |
Correct |
158 ms |
560 KB |
Output is correct |
38 |
Correct |
50 ms |
404 KB |
Output is correct |
39 |
Correct |
161 ms |
328 KB |
Output is correct |
40 |
Correct |
161 ms |
416 KB |
Output is correct |
41 |
Correct |
163 ms |
448 KB |
Output is correct |
42 |
Correct |
51 ms |
328 KB |
Output is correct |
43 |
Correct |
133 ms |
560 KB |
Output is correct |
44 |
Correct |
161 ms |
432 KB |
Output is correct |
45 |
Correct |
158 ms |
412 KB |
Output is correct |