#ifndef EVAL
#include "grader.cpp"
#endif
#include "chameleon.h"
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pii pair<int, int>
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ll long long
using namespace std;
const int MAXN = 505;
// Query(p) | p is vector<int>
// Answer(a, b)
int n;
bool found[MAXN * 2];
vector <int> cand[MAXN * 2];
vector <int> g[MAXN * 2];
int ans[MAXN * 2];
bool f[MAXN * 2][MAXN * 2];
pii get_para(int x, int y) {
if (x > y) {
swap(x, y);
}
return {x, y};
}
void too_much_query() {
for (int i = 1; i <= n * 2; i++) {
for (int j = 1; j <= n * 2; j++) {
if (i != j) {
vector <int> ask = {i, j};
if (Query(ask) == 1) {
cand[i].pb(j);
}
}
}
if (szof(cand[i]) == 1) {
int x = i, y = cand[i][0];
ans[x] = y;
ans[y] = x;
}
}
for (int i = 1; i <= n * 2; i++) {
if (szof(cand[i]) == 3) {
int a = cand[i][0];
int b = cand[i][1];
int c = cand[i][2];
int to = -1;
if (Query({i, a, b}) == 1) {
f[i][c] = f[c][i] = 1;
to = c;
}
else if (Query({i, a, c}) == 1) {
f[i][b] = f[b][i] = 1;
to = b;
}
else {
f[i][a] = f[a][i] = 1;
to = a;
}
}
}
for (int i = 1; i <= n * 2; i++) {
if (!ans[i]) {
set <int> st;
for (int el : cand[i]) {
st.insert(el);
}
for (int j = 1; j <= n * 2; j++) {
if (f[i][j]) {
st.erase(j);
}
}
int need = *st.begin();
ans[i] = need;
ans[need] = i;
}
}
set <pii> omg;
for (int i = 1; i <= n * 2; i++) {
omg.insert(get_para(i, ans[i]));
}
for (auto [x, y] : omg) {
Answer(x, y);
}
}
int find_pos(vector <int> vec, int my_pos) {
if (szof(vec) == 1) {
return vec[0];
}
int mid = szof(vec) / 2 - 1;
vector <int> left, right;
for (int i = 0; i < szof(vec); i++) {
if (i <= mid) {
left.pb(vec[i]);
}
else {
right.pb(vec[i]);
}
}
int before = Query(left);
left.pb(my_pos);
int after = Query(left);
left.pop_back();
if (before == after) {
return find_pos(left, my_pos);
} else {
return find_pos(right, my_pos);
}
}
void Solve(int N) {
n = N;
if (n <= 50) {
too_much_query();
} else {
for (int i = 1; i <= n * 2; i++) {
if (found[i]) {
continue;
}
vector <int> vec;
for (int j = 1; j <= n * 2; j++) {
if (!found[j] && j != i) {
vec.pb(j);
}
}
int other = find_pos(vec, i);
found[i] = found[other] = 1;
Answer(i, other);
}
}
}
Compilation message
chameleon.cpp: In function 'void too_much_query()':
chameleon.cpp:57:8: warning: variable 'to' set but not used [-Wunused-but-set-variable]
57 | int to = -1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
25 ms |
392 KB |
Output is correct |
4 |
Correct |
22 ms |
408 KB |
Output is correct |
5 |
Correct |
25 ms |
328 KB |
Output is correct |
6 |
Correct |
22 ms |
328 KB |
Output is correct |
7 |
Correct |
31 ms |
404 KB |
Output is correct |
8 |
Correct |
23 ms |
328 KB |
Output is correct |
9 |
Correct |
37 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
328 KB |
Output is correct |
10 |
Correct |
3 ms |
456 KB |
Output is correct |
11 |
Correct |
3 ms |
328 KB |
Output is correct |
12 |
Correct |
3 ms |
456 KB |
Output is correct |
13 |
Correct |
3 ms |
456 KB |
Output is correct |
14 |
Correct |
3 ms |
456 KB |
Output is correct |
15 |
Correct |
3 ms |
328 KB |
Output is correct |
16 |
Correct |
3 ms |
456 KB |
Output is correct |
17 |
Correct |
3 ms |
456 KB |
Output is correct |
18 |
Correct |
3 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
25 ms |
392 KB |
Output is correct |
4 |
Correct |
22 ms |
408 KB |
Output is correct |
5 |
Correct |
25 ms |
328 KB |
Output is correct |
6 |
Correct |
22 ms |
328 KB |
Output is correct |
7 |
Correct |
31 ms |
404 KB |
Output is correct |
8 |
Correct |
23 ms |
328 KB |
Output is correct |
9 |
Correct |
37 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
0 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
3 ms |
456 KB |
Output is correct |
20 |
Correct |
3 ms |
328 KB |
Output is correct |
21 |
Correct |
3 ms |
456 KB |
Output is correct |
22 |
Correct |
3 ms |
456 KB |
Output is correct |
23 |
Correct |
3 ms |
456 KB |
Output is correct |
24 |
Correct |
3 ms |
328 KB |
Output is correct |
25 |
Correct |
3 ms |
456 KB |
Output is correct |
26 |
Correct |
3 ms |
456 KB |
Output is correct |
27 |
Correct |
3 ms |
456 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
0 ms |
328 KB |
Output is correct |
30 |
Incorrect |
1 ms |
328 KB |
Wrong Answer [6] |
31 |
Halted |
0 ms |
0 KB |
- |