#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005;
vector<int> ad[mxN];
vector<int> all[2];
int col[mxN];
int query(vector<int> v, int l, int r, int x) {
vector<int> a;
for (int i = l; i <= r; i++) a.push_back(v[i]);
a.push_back(x);
return Query(a);
}
void dfs(int u) {
all[col[u]].push_back(u);
for (int v : ad[u]) {
if (col[v] == -1) {
col[v] = col[u] ^ 1;
dfs(v);
}
}
}
void search(vector<int> v, int x) {
if (v.empty()) return;
int L = 0, R = v.size() - 1;
while (L <= R) {
if (query(v, L, R, x) == R - L + 2) break;
int lo = L, hi = R;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (query(v, L, mid, x) < mid - L + 2) hi = mid;
else lo = mid + 1;
}
ad[x].push_back(v[hi]);
ad[v[hi]].push_back(x);
L = hi + 1;
}
}
void Solve(int N) {
for (int i = 1; i <= 2 * N; i++) {
search(all[0], i);
search(all[1], i);
all[0].clear();
all[1].clear();
for (int j = 1; j <= i; j++) col[j] = -1;
for (int j = 1; j <= i; j++) {
if (col[j] == -1) col[j] = 0, dfs(j);
}
}
vector<int> ans(2 * N + 1), out(2 * N + 1);
for (int i = 1; i <= 2 * N; i++) {
if (ad[i].size() == 1) {
ans[i] = ad[i][0];
continue;
}
int ii = -1, jj = -1;
for (int j : ad[i]) {
for (int k : ad[i]) {
if (j == k || ii != -1) continue;
if (Query({i, j, k}) == 1) {
ii = j, jj = k;
}
}
}
for (int j : ad[i]) {
if (j != ii && j != jj) out[i] = j;
}
}
for (int i = 1; i <= 2 * N; i++) {
if (ad[i].size() == 1) continue;
for (int j : ad[i]) {
if (j != out[i] && out[j] != i) ans[i] = j;
}
}
for (int i = 1; i <= 2 * N; i++) {
if (i < ans[i]) Answer(i, ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
22 ms |
344 KB |
Output is correct |
4 |
Correct |
22 ms |
564 KB |
Output is correct |
5 |
Correct |
19 ms |
344 KB |
Output is correct |
6 |
Correct |
21 ms |
588 KB |
Output is correct |
7 |
Correct |
20 ms |
564 KB |
Output is correct |
8 |
Correct |
19 ms |
576 KB |
Output is correct |
9 |
Correct |
21 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 |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
43 ms |
568 KB |
Output is correct |
4 |
Correct |
42 ms |
564 KB |
Output is correct |
5 |
Correct |
43 ms |
608 KB |
Output is correct |
6 |
Correct |
42 ms |
592 KB |
Output is correct |
7 |
Correct |
41 ms |
592 KB |
Output is correct |
8 |
Correct |
42 ms |
592 KB |
Output is correct |
9 |
Correct |
49 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
22 ms |
344 KB |
Output is correct |
4 |
Correct |
22 ms |
564 KB |
Output is correct |
5 |
Correct |
19 ms |
344 KB |
Output is correct |
6 |
Correct |
21 ms |
588 KB |
Output is correct |
7 |
Correct |
20 ms |
564 KB |
Output is correct |
8 |
Correct |
19 ms |
576 KB |
Output is correct |
9 |
Correct |
21 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
480 KB |
Output is correct |
28 |
Correct |
1 ms |
356 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
43 ms |
568 KB |
Output is correct |
31 |
Correct |
42 ms |
564 KB |
Output is correct |
32 |
Correct |
43 ms |
608 KB |
Output is correct |
33 |
Correct |
42 ms |
592 KB |
Output is correct |
34 |
Correct |
41 ms |
592 KB |
Output is correct |
35 |
Correct |
42 ms |
592 KB |
Output is correct |
36 |
Correct |
49 ms |
600 KB |
Output is correct |
37 |
Correct |
44 ms |
580 KB |
Output is correct |
38 |
Correct |
22 ms |
344 KB |
Output is correct |
39 |
Correct |
43 ms |
600 KB |
Output is correct |
40 |
Correct |
43 ms |
588 KB |
Output is correct |
41 |
Correct |
44 ms |
592 KB |
Output is correct |
42 |
Correct |
19 ms |
344 KB |
Output is correct |
43 |
Correct |
42 ms |
592 KB |
Output is correct |
44 |
Correct |
46 ms |
592 KB |
Output is correct |
45 |
Correct |
49 ms |
836 KB |
Output is correct |