#include "chameleon.h"
#include <vector>
using namespace std;
vector<int> con[1005];
bool visit[1005];
bool answered[1005];
int l[1005];
void Solve(int N)
{
for (int i = 1; i <= 2 * N; i++)
{
for (int j = i + 1; j <= 2 * N; j++)
{
if (i == j)
continue;
auto q = Query({ i, j });
if (q == 1)
{
con[i].push_back(j);
con[j].push_back(i);
}
}
}
for (int i = 1; i <= 2 * N; i++)
{
if (visit[i])
continue;
if (con[i].size() == 1)
{
Answer(i, con[i][0]);
visit[i] = visit[con[i][0]] = true;
answered[i] = answered[con[i][0]] = true;
continue;
}
if (con[con[i][0]].size() == 1)
{
Answer(i, con[i][0]);
visit[i] = visit[con[i][0]] = true;
answered[i] = answered[con[i][0]] = true;
}
else if (con[con[i][1]].size() == 1)
{
Answer(i, con[i][1]);
visit[i] = visit[con[i][1]] = true;
answered[i] = answered[con[i][1]] = true;
}
else if (con[con[i][2]].size() == 1)
{
Answer(i, con[i][2]);
visit[i] = visit[con[i][2]] = true;
answered[i] = answered[con[i][2]] = true;
}
else
{
vector<int> a = { i, con[i][0], con[i][1] };
vector<int> b = { i, con[i][0], con[i][2] };
vector<int> c = { i, con[i][1], con[i][2] };
auto aq = Query(a);
auto bq = Query(b);
auto cq = Query(c);
if(aq == 1)
{
visit[i] = true;
l[i] = con[i][2];
}
else if (bq == 1)
{
visit[i] = true;
l[i] = con[i][1];
}
else
{
visit[i] = true;
l[i] = con[i][0];
}
}
}
for (int i = 1; i <= 2 * N; i++)
{
if (answered[i])
continue;
for (auto& c : con[i])
{
if (c == l[i] || l[c] == i || answered[c])
continue;
Answer(i, c);
answered[i] = answered[c] = true;
break;
}
}
}
Compilation message
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:68:9: warning: unused variable 'cq' [-Wunused-variable]
68 | auto cq = Query(c);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
24 ms |
320 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
2 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
200 KB |
Output is correct |
15 |
Correct |
1 ms |
200 KB |
Output is correct |
16 |
Correct |
2 ms |
200 KB |
Output is correct |
17 |
Correct |
2 ms |
328 KB |
Output is correct |
18 |
Correct |
2 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Incorrect |
24 ms |
320 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Incorrect |
24 ms |
320 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |