#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=1e3+5;
int vs[nx], v[nx][nx];
vector<int> d[nx], a, b;
void dfs(int u, int c)
{
vs[u]=1;
if (!c) a.push_back(u);
else b.push_back(u);
for (auto v:d[u]) if (!vs[v]) dfs(v, !c);
}
bool search(int l, int r, int cur, vector<int> &x)
{
vector<int> qrs;
qrs.push_back(cur);
for (int i=l; i<=r; i++) qrs.push_back(x[i]);
return Query(qrs)!=qrs.size();
}
void Solve(int N) {
for (int i=2; i<=2*N; i++)
{
a.clear();
b.clear();
for (int j=1; j<=2*N; j++) vs[j]=0;
for (int j=1; j<i; j++) if (!vs[j]) dfs(j, 0);
while (!a.empty()&&search(0, a.size()-1, i, a))
{
int l=0, r=a.size();
while (l<r)
{
int md=(l+r)/2;
if (search(l, md, i, a)) r=md;
else l=md+1;
}
d[i].push_back(a[l]);
d[a[l]].push_back(i);
vector<int> tmp;
for (int i=0; i<l; i++) tmp.push_back(a[i]);
for (int i=l+1; i<a.size(); i++) tmp.push_back(a[i]);
a=tmp;
}
while (!b.empty()&&search(0, b.size()-1, i, b))
{
int l=0, r=b.size();
while (l<r)
{
int md=(l+r)/2;
if (search(l, md, i, b)) r=md;
else l=md+1;
}
d[i].push_back(b[l]);
d[b[l]].push_back(i);
vector<int> tmp;
for (int i=0; i<l; i++) tmp.push_back(b[i]);
for (int i=l+1; i<b.size(); i++) tmp.push_back(b[i]);
b=tmp;
}
}
for (int j=1; j<=2*N; j++) vs[j]=0;
for (int i=1; i<=2*N; i++)
{
if (vs[i]) continue;
if (d[i].size()==1)
{
Answer(i, d[i][0]);
vs[i]=vs[d[i][0]]=1;
continue;
}
bool f=0;
for (int j=0; j<2; j++)
{
vector<int> qrs;
qrs.push_back(i);
for (int k=0; k<3; k++) if (k!=j) qrs.push_back(d[i][k]);
if (Query(qrs)==1)
{
f=1;
v[i][d[i][j]]=v[d[i][j]][i]=1;
break;
}
}
if (!f) v[i][d[i][2]]=v[d[i][2]][i]=1;
}
for (int i=1; i<=2*N; i++)
{
if (vs[i]) continue;
for (int j=0; j<3; j++) if (!vs[i]&&!vs[d[i][j]]&&!v[i][d[i][j]]) vs[i]=vs[d[i][j]]=1, Answer(i, d[i][j]);
}
}
Compilation message
chameleon.cpp: In function 'bool search(int, int, int, std::vector<int>&)':
chameleon.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | return Query(qrs)!=qrs.size();
| ~~~~~~~~~~^~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:47:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i=l+1; i<a.size(); i++) tmp.push_back(a[i]);
| ~^~~~~~~~~
chameleon.cpp:63:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i=l+1; i<b.size(); i++) tmp.push_back(b[i]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
13 ms |
520 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
512 KB |
Output is correct |
6 |
Correct |
15 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
496 KB |
Output is correct |
8 |
Correct |
13 ms |
344 KB |
Output is correct |
9 |
Correct |
13 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
30 ms |
4316 KB |
Output is correct |
4 |
Correct |
31 ms |
4432 KB |
Output is correct |
5 |
Correct |
31 ms |
4336 KB |
Output is correct |
6 |
Correct |
31 ms |
4432 KB |
Output is correct |
7 |
Correct |
32 ms |
4432 KB |
Output is correct |
8 |
Correct |
30 ms |
4440 KB |
Output is correct |
9 |
Correct |
30 ms |
4372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
13 ms |
520 KB |
Output is correct |
4 |
Correct |
13 ms |
344 KB |
Output is correct |
5 |
Correct |
13 ms |
512 KB |
Output is correct |
6 |
Correct |
15 ms |
344 KB |
Output is correct |
7 |
Correct |
13 ms |
496 KB |
Output is correct |
8 |
Correct |
13 ms |
344 KB |
Output is correct |
9 |
Correct |
13 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2532 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
30 ms |
4316 KB |
Output is correct |
31 |
Correct |
31 ms |
4432 KB |
Output is correct |
32 |
Correct |
31 ms |
4336 KB |
Output is correct |
33 |
Correct |
31 ms |
4432 KB |
Output is correct |
34 |
Correct |
32 ms |
4432 KB |
Output is correct |
35 |
Correct |
30 ms |
4440 KB |
Output is correct |
36 |
Correct |
30 ms |
4372 KB |
Output is correct |
37 |
Correct |
31 ms |
4176 KB |
Output is correct |
38 |
Correct |
13 ms |
344 KB |
Output is correct |
39 |
Correct |
34 ms |
4176 KB |
Output is correct |
40 |
Correct |
30 ms |
4432 KB |
Output is correct |
41 |
Correct |
30 ms |
4388 KB |
Output is correct |
42 |
Correct |
13 ms |
344 KB |
Output is correct |
43 |
Correct |
30 ms |
4324 KB |
Output is correct |
44 |
Correct |
29 ms |
4384 KB |
Output is correct |
45 |
Correct |
31 ms |
4176 KB |
Output is correct |