#include "chameleon.h"
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
void Solve(int n) {
vector <vector <int>> g(2 * n);
int cnt_qr = 0;
map <vector <int>, int> ans;
function <int(vector <int>)> my_query = [&] (const vector <int> &p) {
vector <int> a = p;
sort(a.begin(), a.end());
for (int &x : a) ++x;
if (!ans.count(a)) {
++cnt_qr;
ans[a] = Query(a);
}
return ans[a];
};
for (int v = 0; v < 2 * n; ++v) {
if (!g[v].empty()) continue;
vector <vector <int>> q;
q.push_back({});
for (int i = 0; i < 2 * n; ++i) if (i != v) q.back().push_back(i);
int alive = 1;
while (!q.empty()) {
vector <vector <int>> nq;
for (auto a : q) {
if (a.size() == 1) {
g[v].push_back(a[0]);
g[a[0]].push_back(v);
} else {
vector <int> b, c;
int m = a.size() / 2;
for (int i = 0; i < m; ++i) b.push_back(a[i]);
for (int i = m; i < (int)a.size(); ++i) c.push_back(a[i]);
b.push_back(v);
c.push_back(v);
bool fl = (my_query(b) != (int)b.size());
if (!fl) {
c.pop_back();
nq.push_back(c);
} else {
b.pop_back();
nq.push_back(b);
if (alive < 3 && my_query(c) != (int)c.size()) {
++alive;
c.pop_back();
nq.push_back(c);
}
}
}
}
q = nq;
}
}
vector <int> who(2 * n, -1);
vector <set <int>> bad(2 * n);
for (int i = 0; i < 2 * n; ++i) {
if (g[i].size() == 1) {
who[i] = g[i][0];
who[g[i][0]] = i;
} else if (g[i].size() == 3) {
for (int j = 0; j < 3; ++j) {
vector <int> p = {i};
for (int k = 0; k < 3; ++k) {
if (k != j) p.push_back(g[i][k]);
}
if (my_query(p) == 1) {
bad[i].insert(g[i][j]);
bad[g[i][j]].insert(i);
}
}
} else {
assert(false);
}
}
for (int i = 0; i < 2 * n; ++i) {
if (who[i] == -1) {
for (int j = 0; j < (int)g[i].size(); ++j) {
if (!bad[i].count(g[i][j])) {
who[i] = g[i][j];
}
}
}
}
for (int i = 0; i < 2 * n; ++i) {
if (who[i] > i) {
Answer(i + 1, who[i] + 1);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Incorrect |
182 ms |
7544 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Runtime error |
6 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Runtime error |
6 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
98 ms |
4484 KB |
Output is correct |
4 |
Correct |
89 ms |
4472 KB |
Output is correct |
5 |
Correct |
91 ms |
4472 KB |
Output is correct |
6 |
Correct |
90 ms |
4472 KB |
Output is correct |
7 |
Correct |
89 ms |
4544 KB |
Output is correct |
8 |
Correct |
89 ms |
4472 KB |
Output is correct |
9 |
Correct |
90 ms |
4472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Incorrect |
182 ms |
7544 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |