// M
#include<bits/stdc++.h>
#include "chameleon.h"
#define pb push_back
using namespace std;
const int N = 505 * 2;
int M[N], MC[N];
vector < int > V[N];
void Recur(vector < int > vec)
{
for (int i = 0; i < (int)vec.size(); i ++)
if (V[vec[i]].size() == 3)
swap(vec[i], vec.back()), vec.pop_back(), i --;
if (!vec.size())
return ;
/*printf("Now : ");
for (int i : vec)
printf("%d ", i);
printf("\n");
fflush(stdout);*/
vector < int > tmp, bad;
tmp.pb(vec[0]);
for (int i = 1; i < (int)vec.size(); i ++)
{
tmp.pb(vec[i]);
if (Query(tmp) == (int)tmp.size())
continue;
else
bad.pb(vec[i]), tmp.pop_back();
}
assert((int)tmp.size() >= (int)vec.size() / 4);
for (int i : bad)
{
int le = 0, ri = (int)tmp.size(), md;
while (true)
{
vector < int > ff(tmp.begin() + le, tmp.begin() + ri);
ff.pb(i);
if (le > 0 && Query(ff) == (int)ff.size())
break;
while (ri - le > 1)
{
md = (le + ri) >> 1;
ff = vector < int > (tmp.begin() + le, tmp.begin() + md);
ff.pb(i);
if (Query(ff) == (int)ff.size())
le = md;
else
ri = md;
}
V[i].push_back(tmp[le]);
V[tmp[le]].push_back(i);
le ++;
ri = (int)tmp.size();
}
}
Recur(bad);
}
void Solve(int n)
{
vector < int > vec;
for (int i = 1; i <= n + n; i ++)
vec.push_back(i);
Recur(vec);
for (int i = 1; i <= n + n; i ++)
if (V[i].size() == 1) // Part of a cycle of length 2
{
MC[i] = V[i][0];
MC[V[i][0]] = i;
}
for (int i = 1; i <= n + n; i ++)
if (MC[i] == 0)
{
assert((int)V[i].size() == 3);
vector < int > All;
memset(M, 0, sizeof(M));
M[i] = 1;
for (int a : V[i])
M[a] = 1;
for (int v = 1; v <= n + n; v ++)
if (!M[v])
All.pb(v);
for (int a : V[i])
{
vector < int > tmp(All.begin(), All.end());
for (int b : V[i])
if (a != b)
tmp.pb(b);
if (Query(tmp) < n)
{
MC[i] = a;
MC[a] = i;
break;
}
}
assert(MC[i]);
}
for (int i = 1; i <= n + n; i ++)
if (i < MC[i])
Answer(i, MC[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
15 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
384 KB |
Output is correct |
5 |
Correct |
21 ms |
512 KB |
Output is correct |
6 |
Correct |
15 ms |
384 KB |
Output is correct |
7 |
Correct |
15 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
384 KB |
Output is correct |
9 |
Correct |
15 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
37 ms |
384 KB |
Output is correct |
4 |
Correct |
38 ms |
384 KB |
Output is correct |
5 |
Correct |
37 ms |
384 KB |
Output is correct |
6 |
Correct |
38 ms |
384 KB |
Output is correct |
7 |
Correct |
38 ms |
384 KB |
Output is correct |
8 |
Correct |
37 ms |
384 KB |
Output is correct |
9 |
Correct |
38 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
15 ms |
384 KB |
Output is correct |
4 |
Correct |
15 ms |
384 KB |
Output is correct |
5 |
Correct |
21 ms |
512 KB |
Output is correct |
6 |
Correct |
15 ms |
384 KB |
Output is correct |
7 |
Correct |
15 ms |
384 KB |
Output is correct |
8 |
Correct |
15 ms |
384 KB |
Output is correct |
9 |
Correct |
15 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
0 ms |
384 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
37 ms |
384 KB |
Output is correct |
31 |
Correct |
38 ms |
384 KB |
Output is correct |
32 |
Correct |
37 ms |
384 KB |
Output is correct |
33 |
Correct |
38 ms |
384 KB |
Output is correct |
34 |
Correct |
38 ms |
384 KB |
Output is correct |
35 |
Correct |
37 ms |
384 KB |
Output is correct |
36 |
Correct |
38 ms |
384 KB |
Output is correct |
37 |
Correct |
39 ms |
384 KB |
Output is correct |
38 |
Correct |
15 ms |
384 KB |
Output is correct |
39 |
Correct |
40 ms |
384 KB |
Output is correct |
40 |
Correct |
38 ms |
384 KB |
Output is correct |
41 |
Correct |
39 ms |
384 KB |
Output is correct |
42 |
Correct |
15 ms |
384 KB |
Output is correct |
43 |
Correct |
38 ms |
460 KB |
Output is correct |
44 |
Correct |
39 ms |
384 KB |
Output is correct |
45 |
Correct |
40 ms |
504 KB |
Output is correct |