# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120663 |
2019-06-25T07:30:32 Z |
윤교준(#2960) |
Minerals (JOI19_minerals) |
C++14 |
|
103 ms |
4364 KB |
#include "minerals.h"
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
using namespace std;
typedef pair<int, int> pii;
mt19937 mtrd(time(0));
const int MAXN = 100055;
bitset<MAXN> chk;
int ask(int c) {
chk[c] = !chk[c];
return Query(c);
}
vector<pii> AnsV;
int Delta;
void solve(vector<int> A, vector<int> B) {
int N = sz(A), M = N >> 1, K = N-M;
if(N < 1) return;
if(1 == N) {
AnsV.eb(A[0], B[0]);
if(chk[A[0]] || chk[B[0]]) Delta++;
return;
}
shuffle(allv(A), mtrd);
shuffle(allv(B), mtrd);
vector<int> AL, AR, BL, BR;
if(!chk[A[0]] && !chk[B[0]]) { // off off
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(1 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 1;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 2;
}
return;
}
if(3 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(1 == ret) {
AnsV.eb(A[0], B[0]);
Delta++;
solve({A[1], A[2]}, {B[1], B[2]});
return;
}
ret = ask(B[1]) - Delta;
if(2 == ret) {
AnsV.eb(A[0], B[1]);
ret = ask(A[1]) - Delta;
if(2 == ret) {
AnsV.eb(A[1], B[0]);
AnsV.eb(A[2], B[2]);
Delta += 2;
return;
}
AnsV.eb(A[2], B[0]);
AnsV.eb(A[1], B[2]);
Delta += 3;
return;
}
AnsV.eb(A[0], B[2]);
Delta++;
solve({A[1], A[2]}, {B[0], B[1]});
return;
}
for(int i = 0; i < M; i++) {
ask(A[i]);
AL.eb(A[i]);
}
for(int i = M; i < N; i++) AR.eb(A[i]);
{
int i = 0, h = M;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(h == ret) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
} else if(!chk[A[0]] && chk[B[0]]) { // off on
solve(B, A);
return;
} else if(!chk[B[0]]) { // on off
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(2 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 2;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 1;
}
return;
}
if(3 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(3 == ret) {
AnsV.eb(A[0], B[0]);
Delta++;
solve({A[1], A[2]}, {B[1], B[2]});
return;
}
ret = ask(B[1]) - Delta;
if(3 == ret) {
AnsV.eb(A[0], B[1]);
ret = ask(A[1]) - Delta;
if(3 == ret) {
AnsV.eb(A[1], B[0]);
AnsV.eb(A[2], B[2]);
Delta += 3;
return;
}
AnsV.eb(A[1], B[2]);
AnsV.eb(A[2], B[0]);
Delta += 2;
return;
}
AnsV.eb(A[0], B[2]);
solve({A[1], A[2]}, {B[0], B[1]});
return;
}
for(int i = 0; i < M; i++) AL.eb(A[i]);
for(int i = M; i < N; i++) {
ask(A[i]);
AR.eb(A[i]);
}
{
int i = 0, h = M;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(h == ret) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
} else { // on on
if(2 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(1 == ret) {
AnsV.eb(A[0], B[0]);
AnsV.eb(A[1], B[1]);
Delta += 1;
} else {
AnsV.eb(A[0], B[1]);
AnsV.eb(A[1], B[0]);
Delta += 2;
}
return;
}
if(3 == N) {
ask(A[0]);
int ret = ask(B[0]) - Delta;
if(2 == ret) {
AnsV.eb(A[0], B[0]);
solve({A[1], A[2]}, {B[1], B[2]});
return;
}
ret = ask(B[1]) - Delta;
if(2 == ret) {
AnsV.eb(A[0], B[1]);
ret = ask(A[1]) - Delta;
if(1 == ret) {
AnsV.eb(A[1], B[0]);
AnsV.eb(A[2], B[2]);
Delta++;
return;
}
AnsV.eb(A[1], B[2]);
AnsV.eb(A[2], B[0]);
Delta += 2;
return;
}
AnsV.eb(A[0], B[2]);
Delta++;
solve({A[1], A[2]}, {B[0], B[1]});
return;
}
for(int i = 0; i < M; i++) AL.eb(A[i]);
for(int i = M; i < N; i++) {
ask(A[i]);
AR.eb(A[i]);
}
{
int i = 0, h = N;
for(int v, ret; sz(BL) < M && sz(BR) < K; i++) {
v = B[i];
ret = ask(v) - Delta;
if(ret == h) {
BL.eb(v);
} else {
BR.eb(v);
}
h = ret;
}
if(sz(BL) == M) {
if(sz(BR) < K - sz(BR)) {
for(int v : BR) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BR.eb(B[j]);
} else {
if(sz(BL) < M - sz(BL)) {
for(int v : BL) ask(v);
} else {
for(int j = i; j < N; j++) ask(B[j]);
}
for(int j = i; j < N; j++) BL.eb(B[j]);
}
}
if(chk[BR[0]]) Delta += K;
solve(AL, BL);
if(chk[BR[0]]) Delta -= K;
solve(AR, BR);
}
}
void Solve(int N) {
{
vector<int> O, A, B;
for(int i = 1; i <= N*2; i++) O.eb(i);
shuffle(allv(O), mtrd);
int oi = 0, h = 0;
for(int i, ret; h < N && oi < N*2; oi++) {
i = O[oi];
ret = ask(i);
if(ret == h) {
B.eb(i);
} else {
A.eb(i);
}
h = ret;
}
if(N+N - oi < oi - N) {
for(int i = oi; i < N*2; i++) ask(O[i]);
} else {
for(int v : B) ask(v);
}
for(int i = oi; i < N*2; i++) B.eb(O[i]);
solve(A, B);
}
for(auto &v : AnsV) Answer(v.first, v.second);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
8 ms |
640 KB |
Output is correct |
4 |
Correct |
17 ms |
1172 KB |
Output is correct |
5 |
Correct |
34 ms |
1584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
19 |
Correct |
92 ms |
4000 KB |
Output is correct |
20 |
Correct |
97 ms |
4052 KB |
Output is correct |
21 |
Correct |
100 ms |
4176 KB |
Output is correct |
22 |
Correct |
100 ms |
3952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
19 |
Correct |
92 ms |
4000 KB |
Output is correct |
20 |
Correct |
97 ms |
4052 KB |
Output is correct |
21 |
Correct |
100 ms |
4176 KB |
Output is correct |
22 |
Correct |
100 ms |
3952 KB |
Output is correct |
23 |
Correct |
99 ms |
4080 KB |
Output is correct |
24 |
Correct |
98 ms |
4080 KB |
Output is correct |
25 |
Correct |
92 ms |
4080 KB |
Output is correct |
26 |
Correct |
93 ms |
4080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
19 |
Correct |
92 ms |
4000 KB |
Output is correct |
20 |
Correct |
97 ms |
4052 KB |
Output is correct |
21 |
Correct |
100 ms |
4176 KB |
Output is correct |
22 |
Correct |
100 ms |
3952 KB |
Output is correct |
23 |
Correct |
99 ms |
4080 KB |
Output is correct |
24 |
Correct |
98 ms |
4080 KB |
Output is correct |
25 |
Correct |
92 ms |
4080 KB |
Output is correct |
26 |
Correct |
93 ms |
4080 KB |
Output is correct |
27 |
Correct |
103 ms |
4128 KB |
Output is correct |
28 |
Correct |
103 ms |
4136 KB |
Output is correct |
29 |
Correct |
97 ms |
4200 KB |
Output is correct |
30 |
Correct |
96 ms |
3908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
19 |
Correct |
92 ms |
4000 KB |
Output is correct |
20 |
Correct |
97 ms |
4052 KB |
Output is correct |
21 |
Correct |
100 ms |
4176 KB |
Output is correct |
22 |
Correct |
100 ms |
3952 KB |
Output is correct |
23 |
Correct |
99 ms |
4080 KB |
Output is correct |
24 |
Correct |
98 ms |
4080 KB |
Output is correct |
25 |
Correct |
92 ms |
4080 KB |
Output is correct |
26 |
Correct |
93 ms |
4080 KB |
Output is correct |
27 |
Correct |
103 ms |
4128 KB |
Output is correct |
28 |
Correct |
103 ms |
4136 KB |
Output is correct |
29 |
Correct |
97 ms |
4200 KB |
Output is correct |
30 |
Correct |
96 ms |
3908 KB |
Output is correct |
31 |
Incorrect |
102 ms |
4364 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
8 ms |
640 KB |
Output is correct |
8 |
Correct |
17 ms |
1172 KB |
Output is correct |
9 |
Correct |
34 ms |
1584 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
21 ms |
1280 KB |
Output is correct |
12 |
Correct |
31 ms |
1664 KB |
Output is correct |
13 |
Correct |
30 ms |
1664 KB |
Output is correct |
14 |
Correct |
30 ms |
1592 KB |
Output is correct |
15 |
Correct |
89 ms |
3952 KB |
Output is correct |
16 |
Correct |
88 ms |
3944 KB |
Output is correct |
17 |
Correct |
86 ms |
3972 KB |
Output is correct |
18 |
Correct |
87 ms |
3884 KB |
Output is correct |
19 |
Correct |
92 ms |
4000 KB |
Output is correct |
20 |
Correct |
97 ms |
4052 KB |
Output is correct |
21 |
Correct |
100 ms |
4176 KB |
Output is correct |
22 |
Correct |
100 ms |
3952 KB |
Output is correct |
23 |
Correct |
99 ms |
4080 KB |
Output is correct |
24 |
Correct |
98 ms |
4080 KB |
Output is correct |
25 |
Correct |
92 ms |
4080 KB |
Output is correct |
26 |
Correct |
93 ms |
4080 KB |
Output is correct |
27 |
Correct |
103 ms |
4128 KB |
Output is correct |
28 |
Correct |
103 ms |
4136 KB |
Output is correct |
29 |
Correct |
97 ms |
4200 KB |
Output is correct |
30 |
Correct |
96 ms |
3908 KB |
Output is correct |
31 |
Incorrect |
102 ms |
4364 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |