#include "minerals.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 1e5;
int mk[N];
int la = 0;
bool Ask(int u){
mk[u] ^= 1;
int res = Query(u);
bool ch = la != res;
la = res;
return ch;
}
int norm(vector<int>& A){
int c0 = 0;
int c1 = 0;
int n = A.size();
for(auto x : A)
(mk[x] ? c1 : c0) ++;
return (n / 2) - min(c0, c1);
}
void normalize(vector<int>& A){
int c0 = 0;
int c1 = 0;
int n = A.size();
for(auto x : A)
(mk[x] ? c1 : c0) ++;
int mn = 0, cnt = c0;
if(c0 > c1) mn = 1, cnt = c1;
for(auto x : A){
if(cnt == (n / 2)) break;
if(mn == mk[x]) continue;
cnt ++;
Ask(x);
}
}
void solve(vector<int> A, vector<int> B){
assert(A.size() == B.size());
// random_shuffle(A.begin(), A.end());
// random_shuffle(B.begin(), B.end());
int n = A.size();
if(n == 1){
Answer(A[0], B[0]);
return ;
}
if(norm(A) > norm(B)) swap(A, B);
normalize(A);
sort(A.begin(), A.end(), [&](int i, int j){
return mk[i] > mk[j];
});
int sz = 0;
for(auto x : A) if(mk[x]) sz ++;
vector<int> A2[2], B2[2];
for(int i = 0; i < sz; i++) A2[0].pb(A[i]);
for(int i = sz; i < n; i++) A2[1].pb(A[i]);
for(auto x : B){
if(A2[0].size() == B2[0].size()){
B2[1].pb(x);
continue;
}
if(A2[1].size() == B2[1].size()){
B2[0].pb(x);
continue;
}
bool fl = Ask(x);
B2[fl ? 1 : 0].pb(x);
}
solve(A2[0], B2[0]);
solve(A2[1], B2[1]);
}
void Solve(int n) {
vector<int> A, B;
for(int i = 1; i <= n + n; i++)
if(Ask(i))
A.pb(i);
else
B.pb(i);
solve(A, B);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
328 KB |
Output is correct |
2 |
Correct |
3 ms |
328 KB |
Output is correct |
3 |
Correct |
5 ms |
584 KB |
Output is correct |
4 |
Correct |
15 ms |
840 KB |
Output is correct |
5 |
Correct |
27 ms |
1540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
19 |
Correct |
61 ms |
3460 KB |
Output is correct |
20 |
Correct |
62 ms |
3584 KB |
Output is correct |
21 |
Correct |
59 ms |
3352 KB |
Output is correct |
22 |
Correct |
56 ms |
3188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
19 |
Correct |
61 ms |
3460 KB |
Output is correct |
20 |
Correct |
62 ms |
3584 KB |
Output is correct |
21 |
Correct |
59 ms |
3352 KB |
Output is correct |
22 |
Correct |
56 ms |
3188 KB |
Output is correct |
23 |
Correct |
67 ms |
3664 KB |
Output is correct |
24 |
Correct |
64 ms |
3648 KB |
Output is correct |
25 |
Correct |
57 ms |
3504 KB |
Output is correct |
26 |
Correct |
64 ms |
3264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
19 |
Correct |
61 ms |
3460 KB |
Output is correct |
20 |
Correct |
62 ms |
3584 KB |
Output is correct |
21 |
Correct |
59 ms |
3352 KB |
Output is correct |
22 |
Correct |
56 ms |
3188 KB |
Output is correct |
23 |
Correct |
67 ms |
3664 KB |
Output is correct |
24 |
Correct |
64 ms |
3648 KB |
Output is correct |
25 |
Correct |
57 ms |
3504 KB |
Output is correct |
26 |
Correct |
64 ms |
3264 KB |
Output is correct |
27 |
Correct |
82 ms |
3604 KB |
Output is correct |
28 |
Correct |
65 ms |
3548 KB |
Output is correct |
29 |
Correct |
57 ms |
3616 KB |
Output is correct |
30 |
Correct |
64 ms |
3532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
19 |
Correct |
61 ms |
3460 KB |
Output is correct |
20 |
Correct |
62 ms |
3584 KB |
Output is correct |
21 |
Correct |
59 ms |
3352 KB |
Output is correct |
22 |
Correct |
56 ms |
3188 KB |
Output is correct |
23 |
Correct |
67 ms |
3664 KB |
Output is correct |
24 |
Correct |
64 ms |
3648 KB |
Output is correct |
25 |
Correct |
57 ms |
3504 KB |
Output is correct |
26 |
Correct |
64 ms |
3264 KB |
Output is correct |
27 |
Correct |
82 ms |
3604 KB |
Output is correct |
28 |
Correct |
65 ms |
3548 KB |
Output is correct |
29 |
Correct |
57 ms |
3616 KB |
Output is correct |
30 |
Correct |
64 ms |
3532 KB |
Output is correct |
31 |
Correct |
70 ms |
3892 KB |
Output is correct |
32 |
Correct |
73 ms |
3692 KB |
Output is correct |
33 |
Correct |
58 ms |
3844 KB |
Output is correct |
34 |
Correct |
59 ms |
3508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
3 ms |
328 KB |
Output is correct |
7 |
Correct |
5 ms |
584 KB |
Output is correct |
8 |
Correct |
15 ms |
840 KB |
Output is correct |
9 |
Correct |
27 ms |
1540 KB |
Output is correct |
10 |
Correct |
2 ms |
328 KB |
Output is correct |
11 |
Correct |
16 ms |
1096 KB |
Output is correct |
12 |
Correct |
22 ms |
1472 KB |
Output is correct |
13 |
Correct |
19 ms |
1516 KB |
Output is correct |
14 |
Correct |
22 ms |
1396 KB |
Output is correct |
15 |
Correct |
66 ms |
3500 KB |
Output is correct |
16 |
Correct |
72 ms |
3528 KB |
Output is correct |
17 |
Correct |
58 ms |
3260 KB |
Output is correct |
18 |
Correct |
54 ms |
3336 KB |
Output is correct |
19 |
Correct |
61 ms |
3460 KB |
Output is correct |
20 |
Correct |
62 ms |
3584 KB |
Output is correct |
21 |
Correct |
59 ms |
3352 KB |
Output is correct |
22 |
Correct |
56 ms |
3188 KB |
Output is correct |
23 |
Correct |
67 ms |
3664 KB |
Output is correct |
24 |
Correct |
64 ms |
3648 KB |
Output is correct |
25 |
Correct |
57 ms |
3504 KB |
Output is correct |
26 |
Correct |
64 ms |
3264 KB |
Output is correct |
27 |
Correct |
82 ms |
3604 KB |
Output is correct |
28 |
Correct |
65 ms |
3548 KB |
Output is correct |
29 |
Correct |
57 ms |
3616 KB |
Output is correct |
30 |
Correct |
64 ms |
3532 KB |
Output is correct |
31 |
Correct |
70 ms |
3892 KB |
Output is correct |
32 |
Correct |
73 ms |
3692 KB |
Output is correct |
33 |
Correct |
58 ms |
3844 KB |
Output is correct |
34 |
Correct |
59 ms |
3508 KB |
Output is correct |
35 |
Correct |
71 ms |
3692 KB |
Output is correct |
36 |
Correct |
83 ms |
3816 KB |
Output is correct |
37 |
Correct |
59 ms |
3840 KB |
Output is correct |
38 |
Correct |
60 ms |
3576 KB |
Output is correct |