#include "chameleon.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
const int MAXN = 500 + 10;
int perm[MAXN];
bool found[2 * MAXN];
std::vector <int> candidates[MAXN];
void Solve(int n)
{
for (int i = 1 ; i <= 2 * n ; ++i)
{
for (int j = 1 ; j <= 2 * n ; ++j)
{
if (i == j)
{
continue;
}
if (Query({i, j}) == 1)
{
// std::cout << "here: " << i << ' ' << j << '\n';
candidates[i].push_back(j);
}
}
if (candidates[i].size() == 3)
{
if (Query({candidates[i][0], candidates[i][2], i}) == 1)
{
std::swap(candidates[i].back(), candidates[i][1]);
} else if (Query({candidates[i][1], candidates[i][2], i}) == 1)
{
std::swap(candidates[i].back(), candidates[i][0]);
}
candidates[i].pop_back();
}
// std::cout << "size: " << i << ' ' << candidates[i].size() << '\n';
// for (const int &j : candidates[i]) std::cout << j << ' '; std::cout << '\n';
}
std::iota(perm + 1, perm + 1 + 2 * n, 1);
std::sort(perm + 1, perm + 1 + 2 * n, [&](int x, int y)
{
return candidates[x].size() < candidates[y].size();
});
for (int idx = 1 ; idx <= 2 * n ; ++idx)
{
int i = perm[idx];
if (found[i])
{
continue;
}
if (candidates[i].size() == 1)
{
Answer(i, candidates[i][0]);
found[candidates[i][0]] = true;
// std::cout << "answer: " << i << ' ' << candidates[i][0] << '\n';
continue;
}
assert(candidates[i].size() == 2);
bool shouldBreak = false;
for (const int &j : candidates[i])
{
for (const int &x : candidates[j])
{
if (x == i)
{
// std::cout << "answer: " << i << ' ' << j << '\n';
Answer(i, j);
found[j] = true;
shouldBreak = true;
break;
}
}
if (shouldBreak)
{
break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
15 ms |
344 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 |
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 |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
2 ms |
472 KB |
Output is correct |
15 |
Correct |
2 ms |
352 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
344 KB |
Output is correct |
18 |
Correct |
2 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 |
15 ms |
344 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 |
Incorrect |
15 ms |
344 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |