Submission #120719

# Submission time Handle Problem Language Result Execution time Memory
120719 2019-06-25T10:12:23 Z youngyojun Minerals (JOI19_minerals) C++14
100 / 100
598 ms 5008 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())
#define INF (0x3f3f3f3f)
using namespace std;
typedef pair<int, int> pii;
mt19937 mtrd(time(0));

const int MAXN = 43055;

int __bf;
bool ask(int v) {
	int t = Query(v);
	bool ret = __bf != t;
	__bf = t;
	return ret;
}

int D[MAXN], OP[MAXN];

void f(vector<int> A, vector<int> B, bool flag) {
	int N = sz(A);
	if(!N) return;
	if(1 == N) {
		Answer(A[0], B[0]);
		return;
	}
	shuffle(allv(A), mtrd);
	shuffle(allv(B), mtrd);

	int M = OP[N];
	vector<int> AL, AR, BL, BR;
	for(int i = 0; i < M; i++) {
		AL.eb(A[i]);
		ask(A[i]);
	}
	for(int i = M; i < N; i++) AR.eb(A[i]);

	int oi = 0;
	for(int i; sz(BL) < M && sz(BR) < N-M && oi < N; oi++) {
		i = B[oi];
		((flag ^ ask(i)) ? BR : BL).eb(i);
	}
	for(; oi < N; oi++) (sz(BL) == M ? BR : BL).eb(B[oi]);

	f(AL, BL, !flag);
	f(AR, BR, flag);
}

void precal() {
	D[1] = 0;
	D[2] = 2; OP[2] = 1;
	for(int i = 3; i <= 43000; i++) {
		D[i] = INF; OP[i] = -1;
		for(int j = 1; j*2 <= i; j++) {
			int t = D[j] + D[i-j] + (i+j-1);
			if(D[i] <= t) continue;
			D[i] = t;
			OP[i] = j;
		}
	}
}

void Solve(int N) {
	precal();

	vector<int> A, B, O;
	for(int i = 1; i <= N*2; i++) O.eb(i);
	shuffle(allv(O), mtrd);

	int oi = 0;
	for(int i; sz(A) < N && oi < N*2; oi++) {
		i = O[oi];
		(ask(i) ? A : B).eb(i);
	}
	for(; oi < N*2; oi++) B.eb(O[oi]);

	f(A, B, true);
}
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 486 ms 644 KB Output is correct
2 Correct 492 ms 868 KB Output is correct
3 Correct 502 ms 960 KB Output is correct
4 Correct 498 ms 1400 KB Output is correct
5 Correct 518 ms 2056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
19 Correct 575 ms 4736 KB Output is correct
20 Correct 577 ms 4568 KB Output is correct
21 Correct 592 ms 4552 KB Output is correct
22 Correct 577 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
19 Correct 575 ms 4736 KB Output is correct
20 Correct 577 ms 4568 KB Output is correct
21 Correct 592 ms 4552 KB Output is correct
22 Correct 577 ms 4444 KB Output is correct
23 Correct 584 ms 4600 KB Output is correct
24 Correct 584 ms 4724 KB Output is correct
25 Correct 589 ms 4604 KB Output is correct
26 Correct 587 ms 4596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
19 Correct 575 ms 4736 KB Output is correct
20 Correct 577 ms 4568 KB Output is correct
21 Correct 592 ms 4552 KB Output is correct
22 Correct 577 ms 4444 KB Output is correct
23 Correct 584 ms 4600 KB Output is correct
24 Correct 584 ms 4724 KB Output is correct
25 Correct 589 ms 4604 KB Output is correct
26 Correct 587 ms 4596 KB Output is correct
27 Correct 577 ms 4616 KB Output is correct
28 Correct 579 ms 4592 KB Output is correct
29 Correct 578 ms 4696 KB Output is correct
30 Correct 579 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
19 Correct 575 ms 4736 KB Output is correct
20 Correct 577 ms 4568 KB Output is correct
21 Correct 592 ms 4552 KB Output is correct
22 Correct 577 ms 4444 KB Output is correct
23 Correct 584 ms 4600 KB Output is correct
24 Correct 584 ms 4724 KB Output is correct
25 Correct 589 ms 4604 KB Output is correct
26 Correct 587 ms 4596 KB Output is correct
27 Correct 577 ms 4616 KB Output is correct
28 Correct 579 ms 4592 KB Output is correct
29 Correct 578 ms 4696 KB Output is correct
30 Correct 579 ms 4572 KB Output is correct
31 Correct 594 ms 4780 KB Output is correct
32 Correct 598 ms 4824 KB Output is correct
33 Correct 598 ms 4752 KB Output is correct
34 Correct 583 ms 4504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 752 KB Output is correct
2 Correct 492 ms 636 KB Output is correct
3 Correct 508 ms 760 KB Output is correct
4 Correct 484 ms 656 KB Output is correct
5 Correct 486 ms 644 KB Output is correct
6 Correct 492 ms 868 KB Output is correct
7 Correct 502 ms 960 KB Output is correct
8 Correct 498 ms 1400 KB Output is correct
9 Correct 518 ms 2056 KB Output is correct
10 Correct 486 ms 680 KB Output is correct
11 Correct 508 ms 1672 KB Output is correct
12 Correct 512 ms 2176 KB Output is correct
13 Correct 515 ms 2224 KB Output is correct
14 Correct 515 ms 2088 KB Output is correct
15 Correct 570 ms 4420 KB Output is correct
16 Correct 575 ms 4504 KB Output is correct
17 Correct 570 ms 4504 KB Output is correct
18 Correct 571 ms 4288 KB Output is correct
19 Correct 575 ms 4736 KB Output is correct
20 Correct 577 ms 4568 KB Output is correct
21 Correct 592 ms 4552 KB Output is correct
22 Correct 577 ms 4444 KB Output is correct
23 Correct 584 ms 4600 KB Output is correct
24 Correct 584 ms 4724 KB Output is correct
25 Correct 589 ms 4604 KB Output is correct
26 Correct 587 ms 4596 KB Output is correct
27 Correct 577 ms 4616 KB Output is correct
28 Correct 579 ms 4592 KB Output is correct
29 Correct 578 ms 4696 KB Output is correct
30 Correct 579 ms 4572 KB Output is correct
31 Correct 594 ms 4780 KB Output is correct
32 Correct 598 ms 4824 KB Output is correct
33 Correct 598 ms 4752 KB Output is correct
34 Correct 583 ms 4504 KB Output is correct
35 Correct 581 ms 4640 KB Output is correct
36 Correct 589 ms 5008 KB Output is correct
37 Correct 591 ms 4780 KB Output is correct
38 Correct 578 ms 4596 KB Output is correct