#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj;
vector<int> bi[2];
bool f(int b, int x) {
vector<int> v(1, x);
for (auto &i:bi[b]) v.emplace_back(i);
if (Query(v)==v.size()) return false;
int s=0, e=bi[b].size()-1;
while (s<e) {
int m=(s+e)/2;
vector<int> w(1, x);
for (int j=0; j<=m; j++) w.emplace_back(bi[b][j]);
if (Query(w)==w.size()) s=m+1;
else e=m;
}
adj[x].emplace_back(bi[b][s]);
adj[bi[b][s]].emplace_back(x);
for (int i=s+1; i<bi[b].size(); i++) bi[b][i-s-1]=bi[b][i];
bi[b].resize(bi[b].size()-s-1);
return true;
}
vector<int> vis; int vc;
void dfs(int i, int b) {
vis[i]=vc;
bi[b].emplace_back(i);
for (auto &j:adj[i]) if (vis[j]!=vc) dfs(j, 1-b);
}
void div(int n) {
bi[0].clear();
bi[1].clear();
vc++;
for (int i=1; i<=n; i++) if (vis[i]!=vc) dfs(i, 0);
}
void Solve(int n) {
n*=2;
adj.resize(n+1);
vis.resize(n+1);
for (int i=1; i<=n; i++) {
while (f(0, i));
while (f(1, i));
div(i);
}
auto chk = [&](int x, int y) {
if (adj[x].size()==1||adj[y].size()==1) return true;
int f1=0, f2=0;
vector<int> v(3);
v[0]=x, v[1]=y;
for (auto &i:adj[x]) if (i!=y) {
v[2]=i;
if (Query(v)==1) { f1=1; break; }
}
for (auto &i:adj[y]) if (i!=x) {
v[2]=i;
if (Query(v)==1) { f2=1; break; }
}
return f1&&f2;
};
vector<int> used(n+1);
for (int i=1; i<=n; i++) if (!used[i]) for (auto &j:adj[i]) if (!used[j]&&i<j&&chk(i, j)) {
used[i]=used[j]=1;
Answer(i, j);
adj[j].clear();
break;
}
}
Compilation message
chameleon.cpp: In function 'bool f(int, int)':
chameleon.cpp:12:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | if (Query(v)==v.size()) return false;
| ~~~~~~~~^~~~~~~~~~
chameleon.cpp:19:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if (Query(w)==w.size()) s=m+1;
| ~~~~~~~~^~~~~~~~~~
chameleon.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i=s+1; i<bi[b].size(); i++) bi[b][i-s-1]=bi[b][i];
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
37 ms |
328 KB |
Output is correct |
4 |
Correct |
38 ms |
460 KB |
Output is correct |
5 |
Correct |
37 ms |
328 KB |
Output is correct |
6 |
Correct |
37 ms |
328 KB |
Output is correct |
7 |
Correct |
37 ms |
328 KB |
Output is correct |
8 |
Correct |
37 ms |
348 KB |
Output is correct |
9 |
Correct |
37 ms |
356 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 |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
1 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
1 ms |
200 KB |
Output is correct |
17 |
Correct |
1 ms |
200 KB |
Output is correct |
18 |
Correct |
1 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 |
73 ms |
448 KB |
Output is correct |
4 |
Correct |
76 ms |
392 KB |
Output is correct |
5 |
Correct |
80 ms |
396 KB |
Output is correct |
6 |
Correct |
78 ms |
328 KB |
Output is correct |
7 |
Correct |
74 ms |
484 KB |
Output is correct |
8 |
Correct |
73 ms |
328 KB |
Output is correct |
9 |
Correct |
74 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
37 ms |
328 KB |
Output is correct |
4 |
Correct |
38 ms |
460 KB |
Output is correct |
5 |
Correct |
37 ms |
328 KB |
Output is correct |
6 |
Correct |
37 ms |
328 KB |
Output is correct |
7 |
Correct |
37 ms |
328 KB |
Output is correct |
8 |
Correct |
37 ms |
348 KB |
Output is correct |
9 |
Correct |
37 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
0 ms |
200 KB |
Output is correct |
12 |
Correct |
0 ms |
200 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
0 ms |
200 KB |
Output is correct |
15 |
Correct |
0 ms |
200 KB |
Output is correct |
16 |
Correct |
0 ms |
200 KB |
Output is correct |
17 |
Correct |
0 ms |
200 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
1 ms |
200 KB |
Output is correct |
20 |
Correct |
1 ms |
200 KB |
Output is correct |
21 |
Correct |
1 ms |
200 KB |
Output is correct |
22 |
Correct |
1 ms |
200 KB |
Output is correct |
23 |
Correct |
1 ms |
200 KB |
Output is correct |
24 |
Correct |
1 ms |
200 KB |
Output is correct |
25 |
Correct |
1 ms |
200 KB |
Output is correct |
26 |
Correct |
1 ms |
200 KB |
Output is correct |
27 |
Correct |
1 ms |
200 KB |
Output is correct |
28 |
Correct |
0 ms |
200 KB |
Output is correct |
29 |
Correct |
0 ms |
200 KB |
Output is correct |
30 |
Correct |
73 ms |
448 KB |
Output is correct |
31 |
Correct |
76 ms |
392 KB |
Output is correct |
32 |
Correct |
80 ms |
396 KB |
Output is correct |
33 |
Correct |
78 ms |
328 KB |
Output is correct |
34 |
Correct |
74 ms |
484 KB |
Output is correct |
35 |
Correct |
73 ms |
328 KB |
Output is correct |
36 |
Correct |
74 ms |
328 KB |
Output is correct |
37 |
Correct |
74 ms |
364 KB |
Output is correct |
38 |
Correct |
37 ms |
356 KB |
Output is correct |
39 |
Correct |
77 ms |
364 KB |
Output is correct |
40 |
Correct |
79 ms |
372 KB |
Output is correct |
41 |
Correct |
73 ms |
356 KB |
Output is correct |
42 |
Correct |
39 ms |
352 KB |
Output is correct |
43 |
Correct |
75 ms |
364 KB |
Output is correct |
44 |
Correct |
74 ms |
364 KB |
Output is correct |
45 |
Correct |
74 ms |
364 KB |
Output is correct |