This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*************************************
* author: marvinthang *
* created: 05.12.2023 15:10:01 *
*************************************/
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i-- > 0; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
// end of template
void Solve(int n) {
vector <vector <int>> adj(2 * n);
vector <bool> used(2 * n);
auto answer = [&] (int u, int v) {
Answer(u + 1, v + 1);
used[u] = used[v] = true;
};
auto query = [&] (vector <int> v) {
for (int &x: v) ++x;
return Query(v);
};
vector <int> colors(2 * n);
REP(i, n + n) {
queue <int> q;
fill(colors.begin(), colors.begin() + i, -1);
REP(u, i) if (colors[u] == -1) {
q.push(u);
colors[u] = 0;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v: adj[u]) if (colors[v] == -1) {
colors[v] = !colors[u];
q.push(v);
}
}
}
REP(t, 2) {
vector <int> List {i};
REP(j, i) if (colors[j] == t) List.push_back(j);
REP(t, 3) {
if (query(List) == (int) List.size()) break;
int l = 1, r = (int) List.size() - 2;
while (l <= r) {
int m = l + r >> 1;
if (query(vector<int>(List.begin(), List.begin() + m + 1)) != m + 1) r = m - 1;
else l = m + 1;
}
adj[i].push_back(List[l]);
adj[List[l]].push_back(i);
List.erase(List.begin() + 1, List.begin() + l + 1);
}
}
}
REP(u, 2 * n) if (!used[u] && (int) adj[u].size() == 1) answer(u, adj[u][0]);
vector <vector <bool>> dir(2 * n, vector<bool>(2 * n));
REP(u, 2 * n) if (!used[u]) {
REP(i, 3) {
bool ok = false;
REP(j, i) if (query({u, adj[u][i], adj[u][j]}) == 1) {
swap(adj[u].back(), adj[u][3 - i - j]);
ok = true;
break;
}
if (ok) break;
}
dir[u][adj[u][2]] = true;
}
REP(u, 2 * n) if (!used[u]) {
REP(i, 2) {
int a = adj[u][i], b = adj[u][!i];
if (dir[a][u] || used[a]) {
answer(u, b);
break;
}
}
}
}
Compilation message (stderr)
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:79:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int m = l + r >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |