Submission #515581

# Submission time Handle Problem Language Result Execution time Memory
515581 2022-01-19T09:34:14 Z kostia244 Minerals (JOI19_minerals) C++17
90 / 100
61 ms 3552 KB
#include "minerals.h"
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
bitset<90000> on;
int qcnt = 0;
int uwusgi(int x) {
	on.flip(x);
	qcnt++;
	return Query(x);
}
#define Query uwusgi
void _Solve(int N, vector<int> AA, vector<int> B, int pop, int fi) {
	vector<int> v(1<<pop), V(1<<pop);
	iota(all(v), 0);
 	for(int i = 0; i < 1<<pop; i++) {
		V[i] = fi^(i&1);
		for(int b = 1; b < pop; 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);
	});
	vector<int> A(1<<pop, -1), C(1<<pop);
	for(int i = 0; i < N; i++)
		A[v[i]] = AA[i];
	for(int b = 0; b < pop; b++) {
		int lst = 0, ops = 0, done = 0;
		for(int i = 0; i < 1<<pop; i++) if(A[i] != -1)
			ops += ((i>>b)&1)^on[A[i]];
		if(ops > N-ops)
		for(int i = 0; i < 1<<pop; i++) if(i < (i^(1<<b)))
			swap(A[i], A[i^(1<<b)]);
		for(int i = 0; i < 1<<pop; 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<<pop), cnto(1<<pop);
		for(auto i : C) cnt[i]++;
		for(int i = 0; i < 1<<b; i++) {
			for(int j = 0; j < 1<<(pop-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]);
}
void Solve(int N) {
	vector<int> A, B, X, Y, 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;
		vector<int> pref(N), suf(N);
		for(int I = 0; I < N; I++) {
			int i = ord[I];
			int cc = Query(i);
			pref[I] = lst != cc;
			lst = cc;
		}
		for(int I = 0; I < N; I++) {
			int i = ord[I];
			int cc = Query(i);
			suf[I] = lst != cc;
			lst = cc;
		}
		for(int i = 0; i < N; i++) {
			if(suf[i]&&pref[i]) {
				A.push_back(ord[i]);
			} else {
				(pref[i] ? X : Y).push_back(ord[i]);
			}
		}
		for(int I = N; I < 2*N; I++) {
			int i = ord[I];
			int cc = Query(i);
			(cc == lst ? A : B).push_back(i);
			lst = cc;
		}
		//A - x
		//B - B
	}
	// cout << A.size() << " " << B.size() << endl;
	// int CC = 0;
	// cout << A.size() << " " << (1<<15) << endl;
	// cout << X.size() << " " << (1<<14) << endl;
	for(auto i : B) assert(on[i]);
	_Solve(A.size(), B, A, 15, 1);
	_Solve(X.size(), X, Y, 14, 0);
	// reverse(all(A));
	// reverse(all(B));
	// for(int i = 0; i < 1<<15; i++) A.pop_back(), B.pop_back();
	// _Solve(N-(1<<15), A, B, v);
	// cout << qcnt << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1412 KB Output is correct
2 Correct 11 ms 1480 KB Output is correct
3 Correct 12 ms 1600 KB Output is correct
4 Correct 17 ms 1856 KB Output is correct
5 Correct 25 ms 2112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
19 Correct 61 ms 3420 KB Output is correct
20 Correct 51 ms 3552 KB Output is correct
21 Correct 48 ms 3428 KB Output is correct
22 Correct 50 ms 3272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
19 Correct 61 ms 3420 KB Output is correct
20 Correct 51 ms 3552 KB Output is correct
21 Correct 48 ms 3428 KB Output is correct
22 Correct 50 ms 3272 KB Output is correct
23 Correct 50 ms 3460 KB Output is correct
24 Correct 52 ms 3456 KB Output is correct
25 Correct 58 ms 3464 KB Output is correct
26 Correct 50 ms 3256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
19 Correct 61 ms 3420 KB Output is correct
20 Correct 51 ms 3552 KB Output is correct
21 Correct 48 ms 3428 KB Output is correct
22 Correct 50 ms 3272 KB Output is correct
23 Correct 50 ms 3460 KB Output is correct
24 Correct 52 ms 3456 KB Output is correct
25 Correct 58 ms 3464 KB Output is correct
26 Correct 50 ms 3256 KB Output is correct
27 Correct 50 ms 3492 KB Output is correct
28 Correct 51 ms 3528 KB Output is correct
29 Correct 50 ms 3472 KB Output is correct
30 Correct 60 ms 3336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
19 Correct 61 ms 3420 KB Output is correct
20 Correct 51 ms 3552 KB Output is correct
21 Correct 48 ms 3428 KB Output is correct
22 Correct 50 ms 3272 KB Output is correct
23 Correct 50 ms 3460 KB Output is correct
24 Correct 52 ms 3456 KB Output is correct
25 Correct 58 ms 3464 KB Output is correct
26 Correct 50 ms 3256 KB Output is correct
27 Correct 50 ms 3492 KB Output is correct
28 Correct 51 ms 3528 KB Output is correct
29 Correct 50 ms 3472 KB Output is correct
30 Correct 60 ms 3336 KB Output is correct
31 Correct 57 ms 3540 KB Output is correct
32 Correct 52 ms 3532 KB Output is correct
33 Correct 53 ms 3528 KB Output is correct
34 Correct 61 ms 3388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1360 KB Output is correct
2 Correct 8 ms 1368 KB Output is correct
3 Correct 8 ms 1352 KB Output is correct
4 Correct 8 ms 1352 KB Output is correct
5 Correct 10 ms 1412 KB Output is correct
6 Correct 11 ms 1480 KB Output is correct
7 Correct 12 ms 1600 KB Output is correct
8 Correct 17 ms 1856 KB Output is correct
9 Correct 25 ms 2112 KB Output is correct
10 Correct 12 ms 1352 KB Output is correct
11 Correct 19 ms 1904 KB Output is correct
12 Correct 25 ms 2120 KB Output is correct
13 Correct 25 ms 2104 KB Output is correct
14 Correct 22 ms 2000 KB Output is correct
15 Correct 52 ms 3416 KB Output is correct
16 Correct 49 ms 3380 KB Output is correct
17 Correct 52 ms 3404 KB Output is correct
18 Correct 54 ms 3172 KB Output is correct
19 Correct 61 ms 3420 KB Output is correct
20 Correct 51 ms 3552 KB Output is correct
21 Correct 48 ms 3428 KB Output is correct
22 Correct 50 ms 3272 KB Output is correct
23 Correct 50 ms 3460 KB Output is correct
24 Correct 52 ms 3456 KB Output is correct
25 Correct 58 ms 3464 KB Output is correct
26 Correct 50 ms 3256 KB Output is correct
27 Correct 50 ms 3492 KB Output is correct
28 Correct 51 ms 3528 KB Output is correct
29 Correct 50 ms 3472 KB Output is correct
30 Correct 60 ms 3336 KB Output is correct
31 Correct 57 ms 3540 KB Output is correct
32 Correct 52 ms 3532 KB Output is correct
33 Correct 53 ms 3528 KB Output is correct
34 Correct 61 ms 3388 KB Output is correct
35 Incorrect 55 ms 3540 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -