#include "chameleon.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
namespace C {
const int N = 500;
int ii[4][N * 2], cnt[4];
int ej[N * 2 + 1][3], eo[N * 2 + 1];
int mate[N * 2 + 1];
void append(int i, int j) {
ej[i][eo[i]++] = j, ej[j][eo[j]++] = i;
}
}
void Solve(int n) {
for (int i = 1; i <= n * 2; i++)
for (int c = 0; c < 4; c++) {
C::ii[c][C::cnt[c]++] = i;
if (c == 3 || Query(vector(C::ii[c], C::ii[c] + C::cnt[c])) == C::cnt[c])
break;
C::cnt[c]--;
}
for (int a = 0; a < 4; a++)
for (int h = 0; h < C::cnt[a]; h++) {
int i = C::ii[a][h];
for (int b = a + 1; b < 4; b++) {
int l = 0;
while (l < C::cnt[b]) {
vi v = vector(C::ii[b] + l, C::ii[b] + C::cnt[b]); v.push_back(i);
if (Query(v) < C::cnt[b] - l + 1) {
int lower = l, upper = C::cnt[b];
while (upper - lower > 1) {
int r = (lower + upper) / 2;
v = vector(C::ii[b] + l, C::ii[b] + r); v.push_back(i);
if (Query(v) < r - l + 1)
upper = r;
else
lower = r;
}
C::append(i, C::ii[b][lower]);
l = upper;
} else
break;
}
}
}
for (int i = 1; i <= n * 2; i++)
if (C::eo[i] == 1)
C::mate[i] = C::ej[i][0];
else {
int tmp;
if (Query(vector({i, C::ej[i][0], C::ej[i][2]})) == 1)
tmp = C::ej[i][0], C::ej[i][0] = C::ej[i][1], C::ej[i][1] = tmp;
else if (Query(vector({i, C::ej[i][0], C::ej[i][1]})) == 1)
tmp = C::ej[i][0], C::ej[i][0] = C::ej[i][2], C::ej[i][2] = tmp;
}
for (int i = 1; i <= n * 2; i++)
if (C::eo[i] > 1) {
int j = C::ej[i][1], k = C::ej[i][2];
C::mate[i] = C::eo[j] == 1 || C::ej[j][0] != i ? j : k;
}
for (int i = 1; i <= n * 2; i++)
if (i < C::mate[i])
Answer(i, C::mate[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
372 KB |
Output is correct |
4 |
Correct |
23 ms |
380 KB |
Output is correct |
5 |
Correct |
24 ms |
352 KB |
Output is correct |
6 |
Correct |
23 ms |
336 KB |
Output is correct |
7 |
Correct |
23 ms |
308 KB |
Output is correct |
8 |
Correct |
23 ms |
336 KB |
Output is correct |
9 |
Correct |
23 ms |
380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
288 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
38 ms |
348 KB |
Output is correct |
4 |
Correct |
36 ms |
336 KB |
Output is correct |
5 |
Correct |
35 ms |
300 KB |
Output is correct |
6 |
Correct |
36 ms |
352 KB |
Output is correct |
7 |
Correct |
37 ms |
336 KB |
Output is correct |
8 |
Correct |
37 ms |
352 KB |
Output is correct |
9 |
Correct |
37 ms |
372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
372 KB |
Output is correct |
4 |
Correct |
23 ms |
380 KB |
Output is correct |
5 |
Correct |
24 ms |
352 KB |
Output is correct |
6 |
Correct |
23 ms |
336 KB |
Output is correct |
7 |
Correct |
23 ms |
308 KB |
Output is correct |
8 |
Correct |
23 ms |
336 KB |
Output is correct |
9 |
Correct |
23 ms |
380 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
0 ms |
208 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
0 ms |
208 KB |
Output is correct |
16 |
Correct |
0 ms |
208 KB |
Output is correct |
17 |
Correct |
0 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
288 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
0 ms |
208 KB |
Output is correct |
29 |
Correct |
0 ms |
208 KB |
Output is correct |
30 |
Correct |
38 ms |
348 KB |
Output is correct |
31 |
Correct |
36 ms |
336 KB |
Output is correct |
32 |
Correct |
35 ms |
300 KB |
Output is correct |
33 |
Correct |
36 ms |
352 KB |
Output is correct |
34 |
Correct |
37 ms |
336 KB |
Output is correct |
35 |
Correct |
37 ms |
352 KB |
Output is correct |
36 |
Correct |
37 ms |
372 KB |
Output is correct |
37 |
Correct |
36 ms |
356 KB |
Output is correct |
38 |
Correct |
25 ms |
368 KB |
Output is correct |
39 |
Correct |
36 ms |
372 KB |
Output is correct |
40 |
Correct |
37 ms |
336 KB |
Output is correct |
41 |
Correct |
34 ms |
360 KB |
Output is correct |
42 |
Correct |
24 ms |
336 KB |
Output is correct |
43 |
Correct |
37 ms |
376 KB |
Output is correct |
44 |
Correct |
36 ms |
336 KB |
Output is correct |
45 |
Correct |
35 ms |
360 KB |
Output is correct |