/*************************************
* 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
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:79:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
18 ms |
552 KB |
Output is correct |
4 |
Correct |
18 ms |
600 KB |
Output is correct |
5 |
Correct |
24 ms |
600 KB |
Output is correct |
6 |
Correct |
18 ms |
600 KB |
Output is correct |
7 |
Correct |
18 ms |
600 KB |
Output is correct |
8 |
Correct |
18 ms |
540 KB |
Output is correct |
9 |
Correct |
22 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 |
1 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 |
344 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 |
1 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 |
344 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 |
1 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 |
Correct |
30 ms |
780 KB |
Output is correct |
4 |
Correct |
29 ms |
596 KB |
Output is correct |
5 |
Correct |
29 ms |
536 KB |
Output is correct |
6 |
Correct |
30 ms |
536 KB |
Output is correct |
7 |
Correct |
29 ms |
544 KB |
Output is correct |
8 |
Correct |
29 ms |
604 KB |
Output is correct |
9 |
Correct |
29 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
18 ms |
552 KB |
Output is correct |
4 |
Correct |
18 ms |
600 KB |
Output is correct |
5 |
Correct |
24 ms |
600 KB |
Output is correct |
6 |
Correct |
18 ms |
600 KB |
Output is correct |
7 |
Correct |
18 ms |
600 KB |
Output is correct |
8 |
Correct |
18 ms |
540 KB |
Output is correct |
9 |
Correct |
22 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 |
1 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 |
344 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 |
1 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 |
Correct |
30 ms |
780 KB |
Output is correct |
31 |
Correct |
29 ms |
596 KB |
Output is correct |
32 |
Correct |
29 ms |
536 KB |
Output is correct |
33 |
Correct |
30 ms |
536 KB |
Output is correct |
34 |
Correct |
29 ms |
544 KB |
Output is correct |
35 |
Correct |
29 ms |
604 KB |
Output is correct |
36 |
Correct |
29 ms |
592 KB |
Output is correct |
37 |
Correct |
31 ms |
596 KB |
Output is correct |
38 |
Correct |
18 ms |
600 KB |
Output is correct |
39 |
Correct |
31 ms |
528 KB |
Output is correct |
40 |
Correct |
31 ms |
532 KB |
Output is correct |
41 |
Correct |
31 ms |
540 KB |
Output is correct |
42 |
Correct |
18 ms |
600 KB |
Output is correct |
43 |
Correct |
29 ms |
528 KB |
Output is correct |
44 |
Correct |
32 ms |
600 KB |
Output is correct |
45 |
Correct |
31 ms |
528 KB |
Output is correct |