#define DBG 1
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
#include "chameleon.h"
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) if (DBG) cerr << #x << " = " << x << endl;
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace {
const int MAXN = 1005;
vector<int> adj[MAXN];
int partner[MAXN], loves[MAXN], n;
int col[MAXN];
void addEdge(int u, int v, bool check = 0) {
if (check && Query({u, v}) != 1) {
return;
}
adj[u].pb(v);
adj[v].pb(u);
}
void dfs(int v) {
for (int to : adj[v]) {
if (col[to] == -1) {
col[to] = 1 - col[v];
dfs(to);
}
else if (col[to] == col[v]) {
assert(0);
}
}
}
}
void Solve(int _n) {
n = _n;
for (int i = 1; i <= 2 * n; ++i) {
for (int j = 1; j < i; ++j) {
col[j] = -1;
}
vector<vector<int>> vec(2);
for (int j = 1; j < i; ++j) {
if (col[j] == -1) {
col[j] = 0;
dfs(j);
}
vec[col[j]].pb(j);
}
for (vector<int> v : vec) {
vector<int> tmp = v;
tmp.pb(i);
while (Query(tmp) != tmp.size()) {
int l = 0;
int r = (int)v.size() - 1;
int p = -1;
while (l <= r) {
int mid = (l + r) >> 1;
tmp = {i};
for (int j = 0; j <= mid; ++j) {
tmp.pb(v[j]);
}
if (Query(tmp) == tmp.size()) {
l = mid + 1;
}
else {
r = mid - 1;
p = mid;
}
}
addEdge(i, v[p], 1);
tmp = vector<int>(v.begin() + p + 1, v.end());
v = tmp;
tmp.pb(i);
}
}
}
for (int i = 1; i <= 2 * n; ++i) {
assert(adj[i].size() == 1 || adj[i].size() == 3);
if (adj[i].size() == 1) {
partner[i] = adj[i][0];
continue;
}
while (Query({i, adj[i][0], adj[i][1]}) != 1) {
rotate(adj[i].begin(), adj[i].begin() + 1, adj[i].end());
}
loves[i] = adj[i][2];
}
for (int i = 1; i <= 2 * n; ++i) {
if (loves[adj[i][0]] == i) {
partner[i] = adj[i][1];
}
else {
partner[i] = adj[i][0];
}
}
for (int i = 1; i <= 2 * n; ++i) {
if (i < partner[i]) {
Answer(i, partner[i]);
}
}
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:75:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (Query(tmp) != tmp.size()) {
~~~~~~~~~~~^~~~~~~~~~~~~
chameleon.cpp:88:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (Query(tmp) == tmp.size()) {
~~~~~~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
42 ms |
384 KB |
Output is correct |
4 |
Correct |
42 ms |
572 KB |
Output is correct |
5 |
Correct |
42 ms |
520 KB |
Output is correct |
6 |
Correct |
42 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
452 KB |
Output is correct |
8 |
Correct |
42 ms |
384 KB |
Output is correct |
9 |
Correct |
43 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 |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 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 |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 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 |
5 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 |
69 ms |
384 KB |
Output is correct |
4 |
Correct |
66 ms |
384 KB |
Output is correct |
5 |
Correct |
67 ms |
384 KB |
Output is correct |
6 |
Correct |
67 ms |
384 KB |
Output is correct |
7 |
Correct |
66 ms |
384 KB |
Output is correct |
8 |
Correct |
67 ms |
512 KB |
Output is correct |
9 |
Correct |
66 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
42 ms |
384 KB |
Output is correct |
4 |
Correct |
42 ms |
572 KB |
Output is correct |
5 |
Correct |
42 ms |
520 KB |
Output is correct |
6 |
Correct |
42 ms |
384 KB |
Output is correct |
7 |
Correct |
42 ms |
452 KB |
Output is correct |
8 |
Correct |
42 ms |
384 KB |
Output is correct |
9 |
Correct |
43 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 |
5 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 |
5 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 |
69 ms |
384 KB |
Output is correct |
31 |
Correct |
66 ms |
384 KB |
Output is correct |
32 |
Correct |
67 ms |
384 KB |
Output is correct |
33 |
Correct |
67 ms |
384 KB |
Output is correct |
34 |
Correct |
66 ms |
384 KB |
Output is correct |
35 |
Correct |
67 ms |
512 KB |
Output is correct |
36 |
Correct |
66 ms |
504 KB |
Output is correct |
37 |
Correct |
66 ms |
504 KB |
Output is correct |
38 |
Correct |
41 ms |
448 KB |
Output is correct |
39 |
Correct |
65 ms |
384 KB |
Output is correct |
40 |
Correct |
65 ms |
384 KB |
Output is correct |
41 |
Correct |
65 ms |
504 KB |
Output is correct |
42 |
Correct |
42 ms |
384 KB |
Output is correct |
43 |
Correct |
67 ms |
504 KB |
Output is correct |
44 |
Correct |
67 ms |
504 KB |
Output is correct |
45 |
Correct |
66 ms |
480 KB |
Output is correct |