#include "chameleon.h"
#include <set>
#include <vector>
std::set<int> Adj[1001];
std::vector<int> edges[1001];
std::vector<int> groups[4];
int part[1001];
int threeQuery(int x, int y, int z) {
std::vector<int> q;
q.push_back(x);
q.push_back(y);
q.push_back(z);
return Query(q);
}
int queryRange(int l, int r, int group) {
if(r-l < 1)
return r-l+1;
std::vector<int> q;
for(int i = l; i <= r; i++)
q.push_back(groups[group][i]);
return Query(q);
}
int queryRange(int l, int r, int x, int group) {
std::vector<int> q;
for(int i = l; i <= r; i++)
q.push_back(groups[group][i]);
q.push_back(x);
return Query(q);
}
int count(int l, int r, int x, int group) {
return (r-l+2) - queryRange(l, r, x, group);
}
int bs(int x, int l, int r, int group) {
if(l == r) {
Adj[x].insert(groups[group][l]);
Adj[groups[group][l]].insert(x);
return l;
}
int m = (l+r)/2;
int cl = count(l, m, x, group);
if(cl)
bs(x, l, m, group);
else
bs(x, m+1, r, group);
}
void Solve(int N) {
for(int i = 1; i <= 2*N; i++) {
for(int j = 0; j < 4; j++) {
groups[j].push_back(i);
if(queryRange(0, groups[j].size()-1, j) == groups[j].size()) {
part[i] = j;
break;
}
else
groups[j].pop_back();
}
}
for(int i = 1; i <= 2*N; i++) {
for(int j = 0; j < part[i]; j++) {
int last = 0;
do {
last = bs(i, last, groups[j].size()-1, j)+1;
} while(last < groups[j].size() && Adj[i].size() < 3 && count(last, groups[j].size()-1, i, j));
}
}
for(int i = 1; i <= 2*N; i++) {
if(Adj[i].size() == 3) {
for(std::set<int>::iterator it = Adj[i].begin(); it != Adj[i].end(); it++) {
edges[i].push_back(*it);
}
}
}
for(int i = 1; i <= 2*N; i++) {
if(edges[i].size() == 3) {
int x0 = threeQuery(i, edges[i][1], edges[i][2]);
int x1 = threeQuery(i, edges[i][0], edges[i][2]);
int x;
if(x0 == 1)
x = edges[i][0];
else if(x1 == 1)
x = edges[i][1];
else
x = edges[i][2];
Adj[x].erase(i);
Adj[i].erase(x);
}
}
for(int i = 1; i <= 2*N; i++) {
int j = *Adj[i].begin();
if(i < j)
Answer(i, j);
}
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:61:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(queryRange(0, groups[j].size()-1, j) == groups[j].size()) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
chameleon.cpp:75:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
} while(last < groups[j].size() && Adj[i].size() < 3 && count(last, groups[j].size()-1, i, j));
~~~~~^~~~~~~~~~~~~~~~~~
chameleon.cpp: In function 'int bs(int, int, int, int)':
chameleon.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
4 |
Correct |
25 ms |
512 KB |
Output is correct |
5 |
Correct |
23 ms |
504 KB |
Output is correct |
6 |
Correct |
23 ms |
512 KB |
Output is correct |
7 |
Correct |
23 ms |
384 KB |
Output is correct |
8 |
Correct |
24 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 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 |
4 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 |
384 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 |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
40 ms |
632 KB |
Output is correct |
4 |
Correct |
39 ms |
512 KB |
Output is correct |
5 |
Correct |
39 ms |
512 KB |
Output is correct |
6 |
Correct |
40 ms |
664 KB |
Output is correct |
7 |
Correct |
40 ms |
600 KB |
Output is correct |
8 |
Correct |
39 ms |
616 KB |
Output is correct |
9 |
Correct |
39 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
23 ms |
384 KB |
Output is correct |
4 |
Correct |
25 ms |
512 KB |
Output is correct |
5 |
Correct |
23 ms |
504 KB |
Output is correct |
6 |
Correct |
23 ms |
512 KB |
Output is correct |
7 |
Correct |
23 ms |
384 KB |
Output is correct |
8 |
Correct |
24 ms |
384 KB |
Output is correct |
9 |
Correct |
23 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 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 |
4 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 |
384 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 |
6 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
4 ms |
384 KB |
Output is correct |
30 |
Correct |
40 ms |
632 KB |
Output is correct |
31 |
Correct |
39 ms |
512 KB |
Output is correct |
32 |
Correct |
39 ms |
512 KB |
Output is correct |
33 |
Correct |
40 ms |
664 KB |
Output is correct |
34 |
Correct |
40 ms |
600 KB |
Output is correct |
35 |
Correct |
39 ms |
616 KB |
Output is correct |
36 |
Correct |
39 ms |
632 KB |
Output is correct |
37 |
Correct |
39 ms |
632 KB |
Output is correct |
38 |
Correct |
23 ms |
384 KB |
Output is correct |
39 |
Correct |
41 ms |
512 KB |
Output is correct |
40 |
Correct |
39 ms |
632 KB |
Output is correct |
41 |
Correct |
38 ms |
632 KB |
Output is correct |
42 |
Correct |
23 ms |
512 KB |
Output is correct |
43 |
Correct |
40 ms |
512 KB |
Output is correct |
44 |
Correct |
39 ms |
640 KB |
Output is correct |
45 |
Correct |
40 ms |
512 KB |
Output is correct |