#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
const int MAXN = 1005;
vector<int> adj[MAXN];
int clr[MAXN], ans[MAXN], dest[MAXN], found;
void bs(int l, int r, int x, vector<int> &v){
if (l > r) return;
if (found == 3) return;
vector<int> qv;
for (int i = l; i <= r; i++) qv.push_back(v[i]);
qv.push_back(x);
if (Query(qv) != qv.size()){
if (l == r){
adj[x].push_back(v[l]); adj[v[l]].push_back(x);
found++;
}
else{
int m = (l + r) >> 1;
bs(l, m, x, v); bs(m + 1, r, x, v);
}
}
}
void dfs(int x, int c){
clr[x] = c;
for (int nxt : adj[x])
if (clr[nxt] == -1)
dfs(nxt, 1 - c);
}
} // namespace
void Solve(int N) {
vector<int> grps[2];
for (int i = 1; i <= 2 * N; i++){
found = 0;
bs(0, grps[0].size() - 1, i, grps[0]); bs(0, grps[1].size() - 1, i, grps[1]);
memset(clr, -1, sizeof(clr));
for (int j = 1; j <= i; j++)
if (clr[j] == -1)
dfs(j, 0);
grps[0].clear(); grps[1].clear();
for (int j = 1; j <= i; j++) grps[clr[j]].push_back(j);
}
memset(dest, -1, sizeof(dest));
for (int i = 1; i <= 2 * N; i++){
if (adj[i].size() == 1) ans[i] = adj[i][0];
else{
for (int k = 0; k <= 2; k++){
vector<int> qvec; qvec.push_back(i);
for (int ind = 0; ind <= 2; ind++)
if (ind != k)
qvec.push_back(adj[i][ind]);
if (Query(qvec) == 1){
dest[i] = adj[i][k];
break;
}
}
}
}
for (int i = 1; i <= 2 * N; i++){
if (adj[i].size() == 1) continue;
for (int k = 0; k <= 2; k++)
if (adj[i][k] != dest[i] && dest[adj[i][k]] != i){
ans[i] = adj[i][k];
break;
}
}
for (int i = 1; i <= 2 * N; i++)
if (ans[i] > i)
Answer(i, ans[i]);
}
Compilation message
chameleon.cpp: In function 'void {anonymous}::bs(int, int, int, std::vector<int>&)':
chameleon.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if (Query(qv) != qv.size()){
| ~~~~~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
19 ms |
344 KB |
Output is correct |
4 |
Correct |
17 ms |
344 KB |
Output is correct |
5 |
Correct |
17 ms |
344 KB |
Output is correct |
6 |
Correct |
18 ms |
524 KB |
Output is correct |
7 |
Correct |
17 ms |
344 KB |
Output is correct |
8 |
Correct |
24 ms |
596 KB |
Output is correct |
9 |
Correct |
28 ms |
344 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 |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 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 |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
29 ms |
508 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
19 ms |
344 KB |
Output is correct |
4 |
Correct |
17 ms |
344 KB |
Output is correct |
5 |
Correct |
17 ms |
344 KB |
Output is correct |
6 |
Correct |
18 ms |
524 KB |
Output is correct |
7 |
Correct |
17 ms |
344 KB |
Output is correct |
8 |
Correct |
24 ms |
596 KB |
Output is correct |
9 |
Correct |
28 ms |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Incorrect |
29 ms |
508 KB |
Wrong Answer [3] |
31 |
Halted |
0 ms |
0 KB |
- |