#include "chameleon.h"
#include <vector>
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
namespace {
int variable_example = 1;
} // namespace
const int nmax = 20001;
vector <vector <int> > g(nmax);
vector <vector <int> > col(2);
vector <bool> used(nmax);
void dfs(int v, int c){
col[c].pb(v);
used[v] = true;
for(int to : g[v]){
if(used[to]) continue;
dfs(to, c ^ 1);
}
}
bool ask(int a, int b, int x){
vector <int> vec;
for(int to : col[b]){
if(vec.size() < x)
vec.pb(to);
}
vec.pb(a);
return Query(vec) == vec.size();
}
void Solve(int N) {
int n = N;
for(int i = 1; i <= 2 * n; i++){
for(int j= 1; j < i; j++)
if(!used[j]) dfs(j, 0);
for(int j= 1;j <= i; j++)
used[j] = false;
for(int x = 0; x < 2; x++){
//cout << col[x].size() << "\n";
while(!ask(i, x, col[x].size())){
int l = -1, r = col[x].size();
while(l + 1 < r){
int mid = (l + r) / 2;
if(!ask(i, x, mid + 1)) r = mid;
else l = mid;
}
if(r == col[x].size()) break;
g[i].pb(col[x][r]);
g[col[x][r]].pb(i);
while(r < (int)col[x].size() - 1)
swap(col[x][r], col[x][r + 1]), r++;
col[x].pop_back();
}
}
col[0].clear();
col[1].clear();
}
//vector <bool> used(nmax);
vector <int> love(nmax);
for(int i = 1; i <= 2 * n; i++){
if(g[i].size() == 1){
if(!used[i])Answer(i, g[i][0]);
used[i] = used[g[i][0]] = true;
}
else{
vector <pii> vec;
for(int x = 0; x < 3; x++){
for(int y = x + 1; y < 3; y++){
if(Query({i, g[i][x], g[i][y]}) == 2)
vec.pb({x, y});
}
}
int cnt[3];
fill(cnt, cnt + 3, 0);
for(auto to : vec)
cnt[to.f]++, cnt[to.s]++;
for(int j = 0; j < 3; j++){
if(cnt[j] == 2)
love[i] = g[i][j];
}
}
}
for(int i= 1; i <= n * 2; i++){
if(used[i]) continue;
for(int j = 0; j < 3; j++){
if(love[g[i][j]] != i && love[i] != g[i][j]){
used[g[i][j]] = true, used[i] = true;
Answer(g[i][j], i);
}
}
}
}
Compilation message
chameleon.cpp: In function 'bool ask(int, int, int)':
chameleon.cpp:34:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
34 | if(vec.size() < x)
| ~~~~~~~~~~~^~~
chameleon.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | return Query(vec) == vec.size();
| ~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if(r == col[x].size()) break;
| ~~^~~~~~~~~~~~~~~~
chameleon.cpp: At global scope:
chameleon.cpp:12:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
12 | int variable_example = 1;
| ^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
34 ms |
840 KB |
Output is correct |
4 |
Correct |
36 ms |
820 KB |
Output is correct |
5 |
Correct |
34 ms |
832 KB |
Output is correct |
6 |
Correct |
33 ms |
816 KB |
Output is correct |
7 |
Correct |
33 ms |
820 KB |
Output is correct |
8 |
Correct |
33 ms |
840 KB |
Output is correct |
9 |
Correct |
36 ms |
840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
1 ms |
848 KB |
Output is correct |
4 |
Correct |
1 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
848 KB |
Output is correct |
6 |
Correct |
1 ms |
848 KB |
Output is correct |
7 |
Correct |
1 ms |
848 KB |
Output is correct |
8 |
Correct |
1 ms |
848 KB |
Output is correct |
9 |
Correct |
1 ms |
848 KB |
Output is correct |
10 |
Correct |
2 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
1 ms |
848 KB |
Output is correct |
13 |
Correct |
2 ms |
848 KB |
Output is correct |
14 |
Correct |
2 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
2 ms |
848 KB |
Output is correct |
17 |
Correct |
2 ms |
848 KB |
Output is correct |
18 |
Correct |
2 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
84 ms |
856 KB |
Output is correct |
4 |
Correct |
86 ms |
836 KB |
Output is correct |
5 |
Correct |
83 ms |
832 KB |
Output is correct |
6 |
Correct |
83 ms |
936 KB |
Output is correct |
7 |
Correct |
85 ms |
840 KB |
Output is correct |
8 |
Correct |
83 ms |
848 KB |
Output is correct |
9 |
Correct |
82 ms |
948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
848 KB |
Output is correct |
2 |
Correct |
1 ms |
848 KB |
Output is correct |
3 |
Correct |
34 ms |
840 KB |
Output is correct |
4 |
Correct |
36 ms |
820 KB |
Output is correct |
5 |
Correct |
34 ms |
832 KB |
Output is correct |
6 |
Correct |
33 ms |
816 KB |
Output is correct |
7 |
Correct |
33 ms |
820 KB |
Output is correct |
8 |
Correct |
33 ms |
840 KB |
Output is correct |
9 |
Correct |
36 ms |
840 KB |
Output is correct |
10 |
Correct |
1 ms |
848 KB |
Output is correct |
11 |
Correct |
1 ms |
848 KB |
Output is correct |
12 |
Correct |
1 ms |
848 KB |
Output is correct |
13 |
Correct |
1 ms |
848 KB |
Output is correct |
14 |
Correct |
1 ms |
848 KB |
Output is correct |
15 |
Correct |
1 ms |
848 KB |
Output is correct |
16 |
Correct |
1 ms |
848 KB |
Output is correct |
17 |
Correct |
1 ms |
848 KB |
Output is correct |
18 |
Correct |
1 ms |
848 KB |
Output is correct |
19 |
Correct |
2 ms |
848 KB |
Output is correct |
20 |
Correct |
1 ms |
848 KB |
Output is correct |
21 |
Correct |
1 ms |
848 KB |
Output is correct |
22 |
Correct |
2 ms |
848 KB |
Output is correct |
23 |
Correct |
2 ms |
848 KB |
Output is correct |
24 |
Correct |
1 ms |
848 KB |
Output is correct |
25 |
Correct |
2 ms |
848 KB |
Output is correct |
26 |
Correct |
2 ms |
848 KB |
Output is correct |
27 |
Correct |
2 ms |
848 KB |
Output is correct |
28 |
Correct |
1 ms |
848 KB |
Output is correct |
29 |
Correct |
1 ms |
848 KB |
Output is correct |
30 |
Correct |
84 ms |
856 KB |
Output is correct |
31 |
Correct |
86 ms |
836 KB |
Output is correct |
32 |
Correct |
83 ms |
832 KB |
Output is correct |
33 |
Correct |
83 ms |
936 KB |
Output is correct |
34 |
Correct |
85 ms |
840 KB |
Output is correct |
35 |
Correct |
83 ms |
848 KB |
Output is correct |
36 |
Correct |
82 ms |
948 KB |
Output is correct |
37 |
Correct |
76 ms |
844 KB |
Output is correct |
38 |
Correct |
32 ms |
828 KB |
Output is correct |
39 |
Correct |
76 ms |
840 KB |
Output is correct |
40 |
Correct |
73 ms |
860 KB |
Output is correct |
41 |
Correct |
75 ms |
820 KB |
Output is correct |
42 |
Correct |
35 ms |
824 KB |
Output is correct |
43 |
Correct |
89 ms |
808 KB |
Output is correct |
44 |
Correct |
75 ms |
936 KB |
Output is correct |
45 |
Correct |
74 ms |
840 KB |
Output is correct |