#include "minerals.h"
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
bitset<90000> on;
int uwusgi(int x) {
on.flip(x);
return Query(x);
}
#define Query uwusgi
void Solve(int N) {
vector<int> A, B, C(N), V(1<<16);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
{
vector<int> ord(2*N);
iota(all(ord), 1);
shuffle(all(ord), rng);
int lst = 0;
for(auto i : ord) {
int cc = Query(i);
(cc==lst ? B : A).push_back(i);
lst = cc;
}
}
// int CC = 0;
auto AA = A;
A.assign(1<<16, -1);
vector<int> v(1<<16);
iota(all(v), 0);
// for(int b = 0; b < 16; b++) {
// sort(all(v));
// int lst = 0;
// int i = 0;
// while(i < N) {
// int j = i;
// while(j < N && v[j] == v[i]) j++;
// for(int x = 0; i+x < j; x++)
// v[i+x] |= ((x&1)^lst)<<b;//, cout << ((x&1)^lst) << ",";
// int c = 0;
// for(int p = i; p < j; p++) c += (v[p]>>b)&1;
// // cout << lst << " " << c << " " << j-i+1 << endl;
// if((i-j)%2 == 0) lst ^= 1;
// i = j;
// }
// }
for(int i = 0; i < 1<<16; i++) {
V[i] = 1^(i&1);
for(int b = 1; b < 16; b++) {
V[i] += (i>>b)%2 != (i>>(b-1))%2;
}
}
sort(all(v), [&](auto x, auto y) {
return V[x] < V[y] ||
(V[x] == V[y] && x < y);
});
for(int i = 0; i < N; i++)
A[v[i]] = AA[i];
B.resize(1<<16);
for(int b = 0; b < 16; b++) {
int lst = 0, ops = 0, done = 0;
for(int i = 0; i < 1<<16; i++) if(A[i] != -1)
ops += ((i>>b)&1)^on[A[i]];
if(ops > N-ops)
for(int i = 0; i < 1<<16; i++) if(i < (i^(1<<b)))
swap(A[i], A[i^(1<<b)]);
for(int i = 0; i < 1<<16; i++) if(A[i] != -1)
if(((i>>b)&1)^on[A[i]])
lst = Query(A[i]), done++;
// cout << ops << " " << N-ops << " " << done << endl;
vector<int> cnt(1<<16), cnto(1<<16);
for(auto i : C) cnt[i]++;
for(int i = 0; i < 1<<b; i++) {
for(int j = 0; j < 1<<(16-b); j++) {
int c = i | (j<<b);
if(A[c]!=-1)
cnto[i] += j&1;
}
}
for(int i = 0; i < N; i++) {
if(!cnto[C[i]]) {cnt[C[i]]--;continue;}
if(cnto[C[i]]) {
int qq = -1;
if(cnto[C[i]] == cnt[C[i]] && lst != qq) qq = lst;//cout << "HEY"<<endl;
else
qq = Query(B[i]);
if(lst == qq) cnto[C[i]]--;
C[i] |= (lst == qq)<<b;
lst = qq;
}
cnt[C[i]]--;
}
// for(auto i : C) cout << i << " "; cout << endl;
}
for(int i = 0; i < N; i++)
Answer(A[C[i]], B[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1920 KB |
Output is correct |
2 |
Correct |
13 ms |
1960 KB |
Output is correct |
3 |
Correct |
16 ms |
1956 KB |
Output is correct |
4 |
Correct |
19 ms |
2120 KB |
Output is correct |
5 |
Correct |
24 ms |
2500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
19 |
Correct |
95 ms |
2972 KB |
Output is correct |
20 |
Correct |
52 ms |
3128 KB |
Output is correct |
21 |
Correct |
56 ms |
3040 KB |
Output is correct |
22 |
Correct |
51 ms |
2828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
19 |
Correct |
95 ms |
2972 KB |
Output is correct |
20 |
Correct |
52 ms |
3128 KB |
Output is correct |
21 |
Correct |
56 ms |
3040 KB |
Output is correct |
22 |
Correct |
51 ms |
2828 KB |
Output is correct |
23 |
Correct |
52 ms |
3100 KB |
Output is correct |
24 |
Correct |
63 ms |
3092 KB |
Output is correct |
25 |
Correct |
51 ms |
3076 KB |
Output is correct |
26 |
Correct |
56 ms |
2920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
19 |
Correct |
95 ms |
2972 KB |
Output is correct |
20 |
Correct |
52 ms |
3128 KB |
Output is correct |
21 |
Correct |
56 ms |
3040 KB |
Output is correct |
22 |
Correct |
51 ms |
2828 KB |
Output is correct |
23 |
Correct |
52 ms |
3100 KB |
Output is correct |
24 |
Correct |
63 ms |
3092 KB |
Output is correct |
25 |
Correct |
51 ms |
3076 KB |
Output is correct |
26 |
Correct |
56 ms |
2920 KB |
Output is correct |
27 |
Correct |
60 ms |
3404 KB |
Output is correct |
28 |
Correct |
57 ms |
3356 KB |
Output is correct |
29 |
Correct |
50 ms |
3452 KB |
Output is correct |
30 |
Correct |
51 ms |
3248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
19 |
Correct |
95 ms |
2972 KB |
Output is correct |
20 |
Correct |
52 ms |
3128 KB |
Output is correct |
21 |
Correct |
56 ms |
3040 KB |
Output is correct |
22 |
Correct |
51 ms |
2828 KB |
Output is correct |
23 |
Correct |
52 ms |
3100 KB |
Output is correct |
24 |
Correct |
63 ms |
3092 KB |
Output is correct |
25 |
Correct |
51 ms |
3076 KB |
Output is correct |
26 |
Correct |
56 ms |
2920 KB |
Output is correct |
27 |
Correct |
60 ms |
3404 KB |
Output is correct |
28 |
Correct |
57 ms |
3356 KB |
Output is correct |
29 |
Correct |
50 ms |
3452 KB |
Output is correct |
30 |
Correct |
51 ms |
3248 KB |
Output is correct |
31 |
Correct |
54 ms |
3432 KB |
Output is correct |
32 |
Correct |
60 ms |
3468 KB |
Output is correct |
33 |
Correct |
57 ms |
3480 KB |
Output is correct |
34 |
Correct |
59 ms |
3312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1864 KB |
Output is correct |
2 |
Correct |
12 ms |
1868 KB |
Output is correct |
3 |
Correct |
12 ms |
1864 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
12 ms |
1920 KB |
Output is correct |
6 |
Correct |
13 ms |
1960 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
8 |
Correct |
19 ms |
2120 KB |
Output is correct |
9 |
Correct |
24 ms |
2500 KB |
Output is correct |
10 |
Correct |
12 ms |
1864 KB |
Output is correct |
11 |
Correct |
20 ms |
2288 KB |
Output is correct |
12 |
Correct |
26 ms |
2588 KB |
Output is correct |
13 |
Correct |
25 ms |
2588 KB |
Output is correct |
14 |
Correct |
26 ms |
2528 KB |
Output is correct |
15 |
Correct |
56 ms |
3116 KB |
Output is correct |
16 |
Correct |
50 ms |
3092 KB |
Output is correct |
17 |
Correct |
49 ms |
2996 KB |
Output is correct |
18 |
Correct |
49 ms |
2848 KB |
Output is correct |
19 |
Correct |
95 ms |
2972 KB |
Output is correct |
20 |
Correct |
52 ms |
3128 KB |
Output is correct |
21 |
Correct |
56 ms |
3040 KB |
Output is correct |
22 |
Correct |
51 ms |
2828 KB |
Output is correct |
23 |
Correct |
52 ms |
3100 KB |
Output is correct |
24 |
Correct |
63 ms |
3092 KB |
Output is correct |
25 |
Correct |
51 ms |
3076 KB |
Output is correct |
26 |
Correct |
56 ms |
2920 KB |
Output is correct |
27 |
Correct |
60 ms |
3404 KB |
Output is correct |
28 |
Correct |
57 ms |
3356 KB |
Output is correct |
29 |
Correct |
50 ms |
3452 KB |
Output is correct |
30 |
Correct |
51 ms |
3248 KB |
Output is correct |
31 |
Correct |
54 ms |
3432 KB |
Output is correct |
32 |
Correct |
60 ms |
3468 KB |
Output is correct |
33 |
Correct |
57 ms |
3480 KB |
Output is correct |
34 |
Correct |
59 ms |
3312 KB |
Output is correct |
35 |
Incorrect |
52 ms |
3140 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |