This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Memory2_lib.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(time(0));
void Solve(int t, int n) {
n *= 2;
vector<int> ids;
ids.push_back(0);
ids.push_back(1);
ids.push_back(2);
vector<vector<int>> val(n, vector<int>(n, -1));
auto Ask = [&](int x, int y) {
if (x == y) {
return 0;
}
if (val[x][y] != -1) {
return val[x][y];
}
val[x][y] = val[y][x] = Flip(x, y);
return val[x][y];
};
// cout << Ask(0, 1) << '\n';
vector<int> res(n, -1);
for (int i = 3; i < n; i++) {
ids.push_back(i);
for (int x = 0; x < 4; x++) {
set<int> st;
for (int y = 0; y < 4; y++) {
if (x != y) {
st.insert(Ask(ids[x], ids[y]));
}
}
if ((int) st.size() == 1) {
res[ids[x]] = *st.begin();
vector<int> new_ids;
for (int y = 0; y < 4; y++) {
if (x != y) {
new_ids.push_back(ids[y]);
}
}
ids = new_ids;
break;
}
}
}
auto Output = [&]() {
vector<vector<int>> f(n);
for (int i = 0; i < n; i++) {
f[res[i]].push_back(i);
}
for (int i = 0; i < n / 2; i++) {
Answer(f[i][0], f[i][1], i);
}
};
// for (int i = 0; i < n; i++) {
// cout << res[i] << " ";
// }
// cout << '\n';
vector<int> cnt(n);
for (int i = 0; i < n; i++) {
if (res[i] != -1) {
cnt[res[i]] += 1;
}
}
int mx = -1;
for (int i = 0; i < n / 2; i++) {
if (cnt[i] == 0) {
mx = i;
break;
}
}
int el = -1;
for (int i = 0; i < n / 2; i++) {
if (cnt[i] == 1) {
el = i;
break;
}
}
// cout << el << " " << mx << '\n';
for (int x = 0; x < 3; x++) {
set<int> st;
for (int y = 0; y < 3; y++) {
if (x != y) {
st.insert(Ask(ids[x], ids[y]));
}
}
if ((int) st.size() == 1) {
res[ids[x]] = el;
for (int y = 0; y < 3; y++) {
if (x != y) {
res[ids[y]] = mx;
}
}
break;
}
}
Output();
return;
}
/*
1 3 10000
2 0 1
1 0 2 0 1 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |