#include "chameleon.h"
#include <vector>
#include <iostream>
using namespace std;
const int maxn = 505;
vector<int> g[maxn * 2];
vector<pair<int, int>> v;
bool vis[maxn * 2];
bool query(int x, vector<int> a) // vrati true ak mame menej farieb ako chameleonov
{
a.push_back(x);
return Query(a) < a.size();
}
void dfs(int u, int c, vector<vector<int> >& k)
{
k[c].push_back(u), vis[u] = true;
for (int v : g[u]) if (!vis[v]) dfs(v, c ^ 1, k);
}
void rmv(int a, int b)
{
for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b)
{
g[a].erase(g[a].begin() + i);
break;
}
}
void Solve(int n)
{
for (int i = 2; i <= 2 * n; i++)
{
vector<vector<int> > k(2);
for (int j = 0; j <= i; j++) vis[j] = false;
for (int j = 1; j < i; j++) if (!vis[j]) dfs(j, 0, k);
for (int j = 0; j < 2; j++) while (k[j].size() && query(i, k[j]))
{
int lo = 1, hi = k[j].size();
while (lo < hi)
{
int mi = (lo + hi) >> 1;
if (query(i, vector<int>(k[j].begin(), k[j].begin() + mi))) hi = mi;
else lo = mi + 1;
}
g[i].push_back(k[j][lo - 1]), g[k[j][lo - 1]].push_back(i);
k[j] = vector<int>(k[j].begin() + lo, k[j].end());
}
}
for (int i = 1; i <= 2 * n; i++) if (g[i].size() == 3)
{
for (int j = 0; j < 3; j++) for (int k = 0; k < j; k++)
{
if (Query({ i, g[i][j], g[i][k] }) == 1) v.push_back({ i, g[i][3 ^ j ^ k] });
}
}
for (const pair<int, int>& i : v)
{
rmv(i.first, i.second);
rmv(i.second, i.first);
}
for (int i = 1; i <= 2 * n; i++) if (g[i][0] > i)
{
Answer(i, g[i][0]);
}
}
Compilation message
chameleon.cpp: In function 'bool query(int, std::vector<int>)':
chameleon.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | return Query(a) < a.size();
| ~~~~~~~~~^~~~~~~~~~
chameleon.cpp: In function 'void rmv(int, int)':
chameleon.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < g[a].size(); i++) if (g[a][i] == b)
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
33 ms |
532 KB |
Output is correct |
4 |
Correct |
33 ms |
412 KB |
Output is correct |
5 |
Correct |
32 ms |
412 KB |
Output is correct |
6 |
Correct |
34 ms |
412 KB |
Output is correct |
7 |
Correct |
32 ms |
404 KB |
Output is correct |
8 |
Correct |
32 ms |
416 KB |
Output is correct |
9 |
Correct |
33 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
63 ms |
452 KB |
Output is correct |
4 |
Correct |
64 ms |
416 KB |
Output is correct |
5 |
Correct |
63 ms |
404 KB |
Output is correct |
6 |
Correct |
65 ms |
448 KB |
Output is correct |
7 |
Correct |
63 ms |
428 KB |
Output is correct |
8 |
Correct |
64 ms |
448 KB |
Output is correct |
9 |
Correct |
63 ms |
412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
328 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
33 ms |
532 KB |
Output is correct |
4 |
Correct |
33 ms |
412 KB |
Output is correct |
5 |
Correct |
32 ms |
412 KB |
Output is correct |
6 |
Correct |
34 ms |
412 KB |
Output is correct |
7 |
Correct |
32 ms |
404 KB |
Output is correct |
8 |
Correct |
32 ms |
416 KB |
Output is correct |
9 |
Correct |
33 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
0 ms |
328 KB |
Output is correct |
12 |
Correct |
0 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
0 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
328 KB |
Output is correct |
29 |
Correct |
0 ms |
328 KB |
Output is correct |
30 |
Correct |
63 ms |
452 KB |
Output is correct |
31 |
Correct |
64 ms |
416 KB |
Output is correct |
32 |
Correct |
63 ms |
404 KB |
Output is correct |
33 |
Correct |
65 ms |
448 KB |
Output is correct |
34 |
Correct |
63 ms |
428 KB |
Output is correct |
35 |
Correct |
64 ms |
448 KB |
Output is correct |
36 |
Correct |
63 ms |
412 KB |
Output is correct |
37 |
Correct |
64 ms |
456 KB |
Output is correct |
38 |
Correct |
32 ms |
388 KB |
Output is correct |
39 |
Correct |
63 ms |
412 KB |
Output is correct |
40 |
Correct |
76 ms |
456 KB |
Output is correct |
41 |
Correct |
64 ms |
448 KB |
Output is correct |
42 |
Correct |
32 ms |
392 KB |
Output is correct |
43 |
Correct |
63 ms |
380 KB |
Output is correct |
44 |
Correct |
64 ms |
448 KB |
Output is correct |
45 |
Correct |
63 ms |
560 KB |
Output is correct |