/*************************************
* 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;
REP(j, i) if (colors[j] == t) List.push_back(j);
List.push_back(i);
List.pop_back();
int last = 0;
REP(t, 3) {
int l = last, r = (int) List.size() - 1;
while (l <= r) {
int m = l + r >> 1;
vector <int> v {i};
FORE(j, last, m) v.push_back(List[j]);
if (query(v) != v.size()) r = m - 1;
else l = m + 1;
}
if (l == (int) List.size()) break;
adj[i].push_back(List[l]);
adj[List[l]].push_back(i);
last = 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
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:81:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
81 | int m = l + r >> 1;
| ~~^~~
chameleon.cpp:84:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if (query(v) != v.size()) r = m - 1;
| ~~~~~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
44 ms |
592 KB |
Output is correct |
4 |
Correct |
45 ms |
520 KB |
Output is correct |
5 |
Correct |
48 ms |
600 KB |
Output is correct |
6 |
Correct |
49 ms |
592 KB |
Output is correct |
7 |
Correct |
45 ms |
592 KB |
Output is correct |
8 |
Correct |
44 ms |
592 KB |
Output is correct |
9 |
Correct |
44 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
41 ms |
524 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
44 ms |
592 KB |
Output is correct |
4 |
Correct |
45 ms |
520 KB |
Output is correct |
5 |
Correct |
48 ms |
600 KB |
Output is correct |
6 |
Correct |
49 ms |
592 KB |
Output is correct |
7 |
Correct |
45 ms |
592 KB |
Output is correct |
8 |
Correct |
44 ms |
592 KB |
Output is correct |
9 |
Correct |
44 ms |
592 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
2 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Incorrect |
41 ms |
524 KB |
Wrong Answer [3] |
31 |
Halted |
0 ms |
0 KB |
- |