Submission #433968

# Submission time Handle Problem Language Result Execution time Memory
433968 2021-06-20T12:52:54 Z alishahali1382 Minerals (JOI19_minerals) C++14
100 / 100
125 ms 4208 KB
#include "minerals.h"
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define SZ(x) ((int)x.size())

const int inf=1000000010;
const ll INF=1000000000000001000LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, a, b, t, ans;
int mark[MAXN];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int Ask(int x){
	mark[x]^=1;
	return ans=Query(x);
}
int diff(vi &vec){
	int ted=0;
	for (int x:vec) ted+=mark[x];
	return abs(SZ(vec)/2 - ted);
}

void divide(vi X, vi Y){
	assert(SZ(X)==SZ(Y));
	if (SZ(X)==1){
		Answer(X[0], Y[0]);
		return ;
	}
	// if (rng()%2) swap(X, Y);
	if (diff(X)>diff(Y)) swap(X, Y);
	int sz=SZ(X), mid=sz/2;
	shuffle(all(Y), rng);
	sort(all(X), [](int i, int j){
		return mark[i]>mark[j];
	});
	vi X1, X2, Y1, Y2;
	for (int i=0; i<sz; i++){
		if (i<mid) X1.pb(X[i]);
		else X2.pb(X[i]);
	}

	for (int x:X1) if (!mark[x]) Ask(x);
	for (int x:X2) if (mark[x]) Ask(x);

	for (int y:Y){
		if (SZ(Y1)==mid) Y2.pb(y);
		else if (SZ(Y2)==sz-mid) Y1.pb(y);
		else{
			int last=ans;
			if (Ask(y)==last) Y1.pb(y);
			else Y2.pb(y);
		}
	}
	divide(X1, Y1);
	divide(X2, Y2);
}

void Solve(int _n){
	n=_n;
	vi X, Y, P(2*n);
	iota(all(P), 1);
	shuffle(all(P), rng);
	for (int i:P){
		int last=ans;
		if (/*SZ(X)==n || */Ask(i)==last) Y.pb(i);
		else X.pb(i);
	}
	divide(X, Y);
}

# Verdict Execution time Memory 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 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 328 KB Output is correct
2 Correct 3 ms 456 KB Output is correct
3 Correct 7 ms 584 KB Output is correct
4 Correct 17 ms 968 KB Output is correct
5 Correct 32 ms 1564 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
19 Correct 93 ms 3776 KB Output is correct
20 Correct 87 ms 3816 KB Output is correct
21 Correct 89 ms 3888 KB Output is correct
22 Correct 84 ms 3672 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
19 Correct 93 ms 3776 KB Output is correct
20 Correct 87 ms 3816 KB Output is correct
21 Correct 89 ms 3888 KB Output is correct
22 Correct 84 ms 3672 KB Output is correct
23 Correct 117 ms 4060 KB Output is correct
24 Correct 98 ms 3904 KB Output is correct
25 Correct 89 ms 3908 KB Output is correct
26 Correct 89 ms 3776 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
19 Correct 93 ms 3776 KB Output is correct
20 Correct 87 ms 3816 KB Output is correct
21 Correct 89 ms 3888 KB Output is correct
22 Correct 84 ms 3672 KB Output is correct
23 Correct 117 ms 4060 KB Output is correct
24 Correct 98 ms 3904 KB Output is correct
25 Correct 89 ms 3908 KB Output is correct
26 Correct 89 ms 3776 KB Output is correct
27 Correct 91 ms 4008 KB Output is correct
28 Correct 96 ms 4060 KB Output is correct
29 Correct 90 ms 4040 KB Output is correct
30 Correct 86 ms 3848 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
19 Correct 93 ms 3776 KB Output is correct
20 Correct 87 ms 3816 KB Output is correct
21 Correct 89 ms 3888 KB Output is correct
22 Correct 84 ms 3672 KB Output is correct
23 Correct 117 ms 4060 KB Output is correct
24 Correct 98 ms 3904 KB Output is correct
25 Correct 89 ms 3908 KB Output is correct
26 Correct 89 ms 3776 KB Output is correct
27 Correct 91 ms 4008 KB Output is correct
28 Correct 96 ms 4060 KB Output is correct
29 Correct 90 ms 4040 KB Output is correct
30 Correct 86 ms 3848 KB Output is correct
31 Correct 95 ms 4072 KB Output is correct
32 Correct 94 ms 4088 KB Output is correct
33 Correct 98 ms 4172 KB Output is correct
34 Correct 96 ms 3904 KB Output is correct
# Verdict Execution time Memory 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 328 KB Output is correct
5 Correct 2 ms 328 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 7 ms 584 KB Output is correct
8 Correct 17 ms 968 KB Output is correct
9 Correct 32 ms 1564 KB Output is correct
10 Correct 2 ms 328 KB Output is correct
11 Correct 19 ms 1224 KB Output is correct
12 Correct 27 ms 1564 KB Output is correct
13 Correct 26 ms 1628 KB Output is correct
14 Correct 32 ms 1560 KB Output is correct
15 Correct 98 ms 3748 KB Output is correct
16 Correct 87 ms 3696 KB Output is correct
17 Correct 83 ms 3688 KB Output is correct
18 Correct 80 ms 3620 KB Output is correct
19 Correct 93 ms 3776 KB Output is correct
20 Correct 87 ms 3816 KB Output is correct
21 Correct 89 ms 3888 KB Output is correct
22 Correct 84 ms 3672 KB Output is correct
23 Correct 117 ms 4060 KB Output is correct
24 Correct 98 ms 3904 KB Output is correct
25 Correct 89 ms 3908 KB Output is correct
26 Correct 89 ms 3776 KB Output is correct
27 Correct 91 ms 4008 KB Output is correct
28 Correct 96 ms 4060 KB Output is correct
29 Correct 90 ms 4040 KB Output is correct
30 Correct 86 ms 3848 KB Output is correct
31 Correct 95 ms 4072 KB Output is correct
32 Correct 94 ms 4088 KB Output is correct
33 Correct 98 ms 4172 KB Output is correct
34 Correct 96 ms 3904 KB Output is correct
35 Correct 103 ms 4076 KB Output is correct
36 Correct 125 ms 4160 KB Output is correct
37 Correct 95 ms 4208 KB Output is correct
38 Correct 113 ms 3992 KB Output is correct