#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
{cerr << #a << " = {";\
for(int qwq = (st); qwq <= (n); ++qwq) {\
if(qwq == (st)) cerr << a[qwq];\
else cerr << ", " << a[qwq];\
} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define display(x) ;
#define displaya(a, st, n) ;
#define displayv(v) ;
#define eprintf(...) if(0) fprintf(stderr, "...")
#endif
template<typename A, typename B>
ostream& operator << (ostream& out, const pair<A, B> &p) {
return out << '(' << p.first << ", " << p.second << ')';
}
namespace {
const int maxN = 500 * 2 + 5;
int n;
set<int> G[maxN];
vector<int> fam[maxN][2];
int pa[maxN], side[maxN];
} // namespace
void merge(int x, int y) {
int t = side[x] ^ side[y] ^ 1;
fam[pa[x]][0].insert(fam[pa[x]][0].end(), fam[pa[y]][t].begin(), fam[pa[y]][t].end());
fam[pa[x]][1].insert(fam[pa[x]][1].end(), fam[pa[y]][1^t].begin(), fam[pa[y]][1^t].end());
int py = pa[y];
for(int u : fam[py][0]) pa[u] = pa[x], side[u] ^= t;
for(int u : fam[py][1]) pa[u] = pa[x], side[u] ^= t;
fam[py][0].clear(); fam[py][1].clear();
}
void link(int x, int y) {
eprintf("%d %d\n", x, y);
if(pa[x] != pa[y]) merge(x, y);
else assert(side[x] != side[y]);
G[x].insert(y);
G[y].insert(x);
}
void getadj(int u, vector<int> all) {
display(u); displayv(all);
all.insert(all.begin(), u);
while(Query(all) != all.size()) {
int L = 1, R = (int)all.size() - 1;
while(L < R) {
int M = (L + R) / 2;
vector<int> q(all.begin(), all.begin() + M + 1);
if(Query(q) != q.size()) R = M;
else L = M + 1;
}
link(all[0], all[L]);
all.erase(all.begin() + 1, all.begin() + L + 1);
}
}
void Solve(int n) {
::n = n;
for(int i = 1; i <= 2 * n; ++i) {
pa[i] = i; side[i] = 0; fam[i][0].push_back(i);
vector<int> x, y;
for(int j = 1; j < i; ++j) if(pa[j] == j) {
x.insert(x.end(), fam[j][0].begin(), fam[j][0].end());
y.insert(y.end(), fam[j][1].begin(), fam[j][1].end());
}
getadj(i, x);
getadj(i, y);
}
int sd = 0;
for(int i = 1; i <= 2 * n; ++i) sd += side[i];
assert(sd == n);
for(int i = 1; i <= 2 * n; ++i) assert(G[i].size() == 1 || G[i].size() == 3);
vector<pii> rem;
for(int i = 1; i <= 2 * n; ++i) if(G[i].size() == 3) {
int x = *G[i].begin(), y = *next(G[i].begin()), z = *next(next(G[i].begin()));
if(Query({i, x, y}) == 1) rem.emplace_back(i, z);
else if(Query({i, x, z}) == 1) rem.emplace_back(i, y);
else if(Query({i, y, z}) == 1) rem.emplace_back(i, x);
else assert(false);
}
displayv(rem);
for(auto p : rem)
G[p.first].erase(p.second),
G[p.second].erase(p.first);
for(int i = 1; i <= 2 * n; ++i) {
assert(G[i].size() == 1);
if(*G[i].begin() > i) Answer(i, *G[i].begin());
}
}
Compilation message
chameleon.cpp: In function 'void getadj(int, std::vector<int>)':
chameleon.cpp:60:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(Query(all) != all.size()) {
~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:65:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(Query(q) != q.size()) R = M;
~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
38 ms |
512 KB |
Output is correct |
4 |
Correct |
37 ms |
512 KB |
Output is correct |
5 |
Correct |
36 ms |
512 KB |
Output is correct |
6 |
Correct |
37 ms |
512 KB |
Output is correct |
7 |
Correct |
36 ms |
512 KB |
Output is correct |
8 |
Correct |
39 ms |
512 KB |
Output is correct |
9 |
Correct |
43 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 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 |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 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 |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
6 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
512 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
57 ms |
1656 KB |
Output is correct |
4 |
Correct |
66 ms |
1656 KB |
Output is correct |
5 |
Correct |
63 ms |
1656 KB |
Output is correct |
6 |
Correct |
59 ms |
1656 KB |
Output is correct |
7 |
Correct |
60 ms |
1656 KB |
Output is correct |
8 |
Correct |
59 ms |
1660 KB |
Output is correct |
9 |
Correct |
59 ms |
1700 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 |
38 ms |
512 KB |
Output is correct |
4 |
Correct |
37 ms |
512 KB |
Output is correct |
5 |
Correct |
36 ms |
512 KB |
Output is correct |
6 |
Correct |
37 ms |
512 KB |
Output is correct |
7 |
Correct |
36 ms |
512 KB |
Output is correct |
8 |
Correct |
39 ms |
512 KB |
Output is correct |
9 |
Correct |
43 ms |
512 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 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 |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
6 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
6 ms |
512 KB |
Output is correct |
24 |
Correct |
6 ms |
640 KB |
Output is correct |
25 |
Correct |
5 ms |
512 KB |
Output is correct |
26 |
Correct |
5 ms |
512 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
57 ms |
1656 KB |
Output is correct |
31 |
Correct |
66 ms |
1656 KB |
Output is correct |
32 |
Correct |
63 ms |
1656 KB |
Output is correct |
33 |
Correct |
59 ms |
1656 KB |
Output is correct |
34 |
Correct |
60 ms |
1656 KB |
Output is correct |
35 |
Correct |
59 ms |
1660 KB |
Output is correct |
36 |
Correct |
59 ms |
1700 KB |
Output is correct |
37 |
Correct |
59 ms |
2044 KB |
Output is correct |
38 |
Correct |
40 ms |
512 KB |
Output is correct |
39 |
Correct |
56 ms |
2016 KB |
Output is correct |
40 |
Correct |
57 ms |
1912 KB |
Output is correct |
41 |
Correct |
62 ms |
1912 KB |
Output is correct |
42 |
Correct |
37 ms |
512 KB |
Output is correct |
43 |
Correct |
69 ms |
1796 KB |
Output is correct |
44 |
Correct |
60 ms |
2044 KB |
Output is correct |
45 |
Correct |
59 ms |
1912 KB |
Output is correct |