#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> v, int x) {
if (v.empty()) return false;
v.push_back(x);
return Query(v) != v.size();
}
void Solve(int n) {
n = n * 2;
vector<vector<int>> adj(n + 1);
vector<int> col(n + 1), ans(n + 1);
vector<int> pre(n + 1), nxt(n + 1);
queue<int> que;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++)
col[j] = -1;
for (int j = 1, u; j < i; j++) {
if (col[j] >= 0) continue;
que.push(j); col[j] = 0;
while (que.size()) {
u = que.front(); que.pop();
for (int v : adj[u])
if (col[v] < 0) {
col[v] = 1 - col[u];
que.push(v);
}
}
}
vector<int> half[2];
for (int j = 1; j < i; j++)
half[col[j]].push_back(j);
for (int j = 0; j < 2; j++) {
while (check(half[j], i)) {
int l = 1, r = half[j].size();
while (l < r) {
int m = (l + r) / 2;
if (check(vector<int>
(half[j].begin(),
half[j].begin() + m), i))
r = m;
else l = m + 1;
}
adj[i].push_back(half[j][l - 1]);
adj[half[j][l - 1]].push_back(i);
half[j].erase(half[j].begin(),
half[j].begin() + l);
}
}
}
for (int i = 1; i <= n; i++) {
if (adj[i].size() == 1) continue;
while (Query({i, adj[i][0], adj[i][1]}) != 1)
rotate(adj[i].begin(), adj[i].begin() + 1, adj[i].end());
nxt[i] = adj[i][2]; pre[adj[i][2]] = i;
}
for (int i = 1; i <= n; i++) {
if (adj[i].size() == 1) ans[i] = adj[i][0];
else ans[i] = adj[i][0] + adj[i][1] + adj[i][2] - nxt[i] - pre[i];
if (ans[i] > i) Answer(i, ans[i]);
}
}
Compilation message
chameleon.cpp: In function 'bool check(std::vector<int>, int)':
chameleon.cpp:9:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | return Query(v) != v.size();
| ~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
32 ms |
424 KB |
Output is correct |
4 |
Correct |
34 ms |
388 KB |
Output is correct |
5 |
Correct |
33 ms |
408 KB |
Output is correct |
6 |
Correct |
32 ms |
420 KB |
Output is correct |
7 |
Correct |
34 ms |
412 KB |
Output is correct |
8 |
Correct |
36 ms |
412 KB |
Output is correct |
9 |
Correct |
32 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
51 ms |
336 KB |
Output is correct |
4 |
Correct |
53 ms |
412 KB |
Output is correct |
5 |
Correct |
50 ms |
336 KB |
Output is correct |
6 |
Correct |
51 ms |
400 KB |
Output is correct |
7 |
Correct |
50 ms |
404 KB |
Output is correct |
8 |
Correct |
49 ms |
424 KB |
Output is correct |
9 |
Correct |
51 ms |
544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
32 ms |
424 KB |
Output is correct |
4 |
Correct |
34 ms |
388 KB |
Output is correct |
5 |
Correct |
33 ms |
408 KB |
Output is correct |
6 |
Correct |
32 ms |
420 KB |
Output is correct |
7 |
Correct |
34 ms |
412 KB |
Output is correct |
8 |
Correct |
36 ms |
412 KB |
Output is correct |
9 |
Correct |
32 ms |
312 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
1 ms |
208 KB |
Output is correct |
28 |
Correct |
0 ms |
208 KB |
Output is correct |
29 |
Correct |
0 ms |
208 KB |
Output is correct |
30 |
Correct |
51 ms |
336 KB |
Output is correct |
31 |
Correct |
53 ms |
412 KB |
Output is correct |
32 |
Correct |
50 ms |
336 KB |
Output is correct |
33 |
Correct |
51 ms |
400 KB |
Output is correct |
34 |
Correct |
50 ms |
404 KB |
Output is correct |
35 |
Correct |
49 ms |
424 KB |
Output is correct |
36 |
Correct |
51 ms |
544 KB |
Output is correct |
37 |
Correct |
49 ms |
392 KB |
Output is correct |
38 |
Correct |
33 ms |
396 KB |
Output is correct |
39 |
Correct |
50 ms |
420 KB |
Output is correct |
40 |
Correct |
50 ms |
424 KB |
Output is correct |
41 |
Correct |
51 ms |
400 KB |
Output is correct |
42 |
Correct |
33 ms |
404 KB |
Output is correct |
43 |
Correct |
53 ms |
408 KB |
Output is correct |
44 |
Correct |
49 ms |
412 KB |
Output is correct |
45 |
Correct |
48 ms |
408 KB |
Output is correct |