#include "chameleon.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
const int maxn = 1001, k = 4;
int n;
bool used[maxn];
vector<int> v;
vector<int> s[k];
vector<int> a[maxn], b[maxn];
bool bs(int x){
if(Query(v) == v.size()) return 0;
int l = 0, r = v.size() - 1;
while(r - l > 1){
int mid = (l + r) / 2;
vector<int> v1(v.begin() + l, v.begin() + mid);
v1.push_back(x);
if(Query(v1) == v1.size()) l = mid;
else r = mid;
}
a[x].push_back(v[l]);
a[v[l]].push_back(x);
v.erase(v.begin() + l);
bs(x);
return 1;
}
void Solve(int N){
n = 2 * N;
for(int i = 1; i <= n; i++){
bool t[4] = {};
for(int j = 0; j < k && a[i].size() < 3; j++){
if(s[j].empty()) continue;
v = s[j];
v.push_back(i);
t[j] = bs(i);
}
for(int j = 0; j < k; j++){
if(!t[j]){
s[j].push_back(i);
break;
}
}
}
for(int i = 1; i <= n; i++){
if(a[i].size() == 1) continue;
for(int j = 0; j < 3; j++){
v = a[i];
v.erase(v.begin() + j);
v.push_back(i);
if(Query(v) == 1){
b[i].push_back(a[i][j]);
b[a[i][j]].push_back(i);
break;
}
}
}
for(int i = 1; i <= n; i++){
if(used[i]) continue;
for(int j : a[i]){
if(!count(b[i].begin(), b[i].end(), j)){
Answer(i, j);
used[i] = used[j] = 1;
break;
}
}
}
}
Compilation message
chameleon.cpp: In function 'bool bs(int)':
chameleon.cpp:20:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(v) == v.size()) return 0;
~~~~~~~~~^~~~~~~~~~~
chameleon.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(v1) == v1.size()) l = mid;
~~~~~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
20 ms |
384 KB |
Output is correct |
4 |
Correct |
20 ms |
432 KB |
Output is correct |
5 |
Correct |
20 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
384 KB |
Output is correct |
8 |
Correct |
20 ms |
512 KB |
Output is correct |
9 |
Correct |
20 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
432 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
432 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
404 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
416 KB |
Output is correct |
3 |
Correct |
36 ms |
504 KB |
Output is correct |
4 |
Correct |
36 ms |
504 KB |
Output is correct |
5 |
Correct |
37 ms |
384 KB |
Output is correct |
6 |
Correct |
37 ms |
504 KB |
Output is correct |
7 |
Correct |
37 ms |
384 KB |
Output is correct |
8 |
Correct |
37 ms |
384 KB |
Output is correct |
9 |
Correct |
37 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
20 ms |
384 KB |
Output is correct |
4 |
Correct |
20 ms |
432 KB |
Output is correct |
5 |
Correct |
20 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
384 KB |
Output is correct |
7 |
Correct |
20 ms |
384 KB |
Output is correct |
8 |
Correct |
20 ms |
512 KB |
Output is correct |
9 |
Correct |
20 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
432 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
404 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
416 KB |
Output is correct |
30 |
Correct |
36 ms |
504 KB |
Output is correct |
31 |
Correct |
36 ms |
504 KB |
Output is correct |
32 |
Correct |
37 ms |
384 KB |
Output is correct |
33 |
Correct |
37 ms |
504 KB |
Output is correct |
34 |
Correct |
37 ms |
384 KB |
Output is correct |
35 |
Correct |
37 ms |
384 KB |
Output is correct |
36 |
Correct |
37 ms |
384 KB |
Output is correct |
37 |
Correct |
33 ms |
504 KB |
Output is correct |
38 |
Correct |
19 ms |
384 KB |
Output is correct |
39 |
Correct |
34 ms |
504 KB |
Output is correct |
40 |
Correct |
34 ms |
504 KB |
Output is correct |
41 |
Correct |
34 ms |
512 KB |
Output is correct |
42 |
Correct |
20 ms |
384 KB |
Output is correct |
43 |
Correct |
37 ms |
384 KB |
Output is correct |
44 |
Correct |
34 ms |
504 KB |
Output is correct |
45 |
Correct |
33 ms |
384 KB |
Output is correct |