이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
if (a.empty()) return o << "{}";
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#include "grader.cpp"
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#include "chameleon.h"
#endif
const int mod = 1e9 + 7, N = 100000, logN = 20, K = 48763;
void Solve(int n) {
vector <vector <int>> g(n * 2 + 1), adj(n * 2 + 1);
for (int i = 1; i <= n * 2; ++i) {
for (int j = i + 1; j <= n * 2; ++j) {
if (Query({i, j}) == 1)
g[i].pb(j), g[j].pb(i), test(i, j);
}
}
for (int i = 1; i <= n * 2; ++i) {
if (g[i].size() == 2) {
adj[i] = g[i];
} else if (g[i].size() == 3) {
assert(g[i].size() == 3);
if (Query({i, g[i][0], g[i][1]}) == 1)
adj[i].pb(g[i][2]);
else if (Query({i, g[i][0], g[i][2]}) == 1)
adj[i].pb(g[i][1]);
else
adj[i].pb(g[i][0]);
}
}
vector <bool> vis_dfs(n * 2 + 1, false);
vector <int> cyc;
function <void(int)> dfs = [&](int v) {
vis_dfs[v] = true;
cyc.pb(v);
for (int u : adj[v]) if (!vis_dfs[u])
dfs(u);
};
vector <bool> vis(n * 2 + 1, false);
for (int i = 1; i <= n * 2; ++i) if (!vis[i]) {
int st = i;
cyc.clear(), dfs(st);
// check pair in the same cycle
int m = cyc.size();
if (m >= 6) {
test(cyc);
for (int j = 0; j < m; ++j) if (!vis[cyc[j]]) {
for (int t = (j + 3) % m, cnt = 0; cnt < (m - 4) / 2; ++cnt, t = (t + 2) % m) {
if (Query({cyc[j], cyc[t]}) == 1) {
Answer(cyc[j], cyc[t]);
vis[cyc[j]] = true, vis[cyc[t]] = true;
}
}
}
}
vector <int> p;
for (int i = 1; i <= n * 2; ++i) if (!vis[i] && !count(all(cyc), i))
p.pb(i);
for (int st : cyc) if (!vis[st]) {
if (m == 2)
p.pb(cyc[0] ^ cyc[1] ^ st);
int l = 0, r = p.size();
while (r - l > 1) {
int m = l + r >> 1;
vector <int> now(p.begin() + l, p.begin() + m);
int x = Query(now);
now.pb(st);
int y = Query(now);
if (y == x)
r = m;
else
l = m;
}
Answer(st, p[l]);
vis[st] = vis[p[l]] = true;
if (m == 2)
p.pop_back();
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:105:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
105 | 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... |