답안 #494870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494870 2021-12-17T02:49:31 Z flappybird Minerals (JOI19_minerals) C++14
80 / 100
75 ms 9636 KB
#include "minerals.h"
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
typedef long long ll;
#define ln '\n'
#define MAX 101010
#define C 0.62

ll rnd[MAX];
vector<ll> A, B; //A is old
ll chk[MAX];
ll ans[MAX];
ll rem[MAX];
ll pv = 0;
ll pvv = 0;

ll query(ll x) {
	rem[x] = !rem[x];
	pv = pvv;
	pvv = Query(rnd[x]);
	return pvv;
}

void answer(ll x, ll y) {
	Answer(rnd[x], rnd[y]);
}

void dnc(vector<ll> v1, vector<ll> v2) {
	ll N = v1.size();
	if (N == 1) {
		ans[v1[0]] = v2[0];
		return;
	}
	if (N == 2) {
		if (!rem[B[v2[0]]]||!rem[B[v2[0]]]) query(B[v2[0]]);
		if (rem[B[v2[0]]]) {
			if (rem[B[v2[1]]]) query(B[v2[1]]);
			ans[v1[0]] = v2[0];
			ans[v1[1]] = v2[1];
			if (query(A[v1[0]]) != pv) swap(ans[v1[0]], ans[v1[1]]);
		}
		else {
			if (rem[B[v2[0]]]) query(B[v2[0]]);
			ans[v1[0]] = v2[1];
			ans[v1[1]] = v2[0];
			if (query(A[v1[0]]) != pv) swap(ans[v1[0]], ans[v1[1]]);
		}
		return;
	}
	ll i;
	vector<ll> in, out;
	for (i = 0; i < N; i++) (rem[B[v2[i]]] ? in : out).push_back(v2[i]);
	ll sz = N * C;
	while (in.size() < sz) {
		ll a = out.back();
		out.pop_back();
		query(B[a]);
		in.push_back(a);
	}
	while (in.size() > sz) {
		ll a = in.back();
		in.pop_back();
		query(B[a]);
		out.push_back(a);
	}
	vector<ll> in1, out1;
	for (i = 0; i < N; i++) {
		if (pv == query(A[v1[i]])) in1.push_back(v1[i]);
		else out1.push_back(v1[i]);
	}
	dnc(in1, in);
	dnc(out1, out);
}

void rnd_gen(ll N) {
	//mt19937 engine((unsigned int)time(NULL));
	//uniform_int_distribution<int> distribution(0, 1000000000);
	//auto generator = bind(distribution, engine);
	ll i;
	ll j;
	for (i = 1; i <= 2 * N; i++) rnd[i] = i;
	for (j = 0; j < 2; j++) {
		for (i = 2 * N; i > 1; i--) {
			ll a = rand() % i + 1;
			swap(rnd[i], rnd[a]);
		}
	}
}

ll anschk[MAX];
ll num[MAX];
ll checked[MAX];

void Solve(int N) {
	mt19937 engine((unsigned int)time(NULL));
	uniform_int_distribution<int> distribution(0, 1000000000);
	auto generator = bind(distribution, engine);
	ll i;
	rnd_gen(N);
	for (i = 1; i <= 2 * N; i++) {
		ll res = query(i);
		if (res != pv) {
			B.push_back(i);
			chk[i] = 1;
		}
		else {
			A.push_back(i);
			num[A.size() - 1] = B.size();
			chk[i] = 0;
		}
	}
	for (i = 1; i <= 2 * N; i++) rem[i] = 1, checked[i] = 16;
	for (i = 1; i <= 2 * N; i++) {
		for (ll j = 15; j >= 0; j--) {
			if (num[i] < (1LL << j)) {
				checked[i] = j;
			}
		}
	}
	vector<ll> v;
	for (i = 0; i < N; i++) v.push_back(i);
	dnc(v, v);
	for (i = 0; i < N; i++) answer(A[i], B[ans[i]]);
}

Compilation message

minerals.cpp: In function 'void dnc(std::vector<long long int>, std::vector<long long int>)':
minerals.cpp:55:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   55 |  while (in.size() < sz) {
      |         ~~~~~~~~~~^~~~
minerals.cpp:61:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   61 |  while (in.size() > sz) {
      |         ~~~~~~~~~~^~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:98:7: warning: variable 'generator' set but not used [-Wunused-but-set-variable]
   98 |  auto generator = bind(distribution, engine);
      |       ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 456 KB Output is correct
2 Correct 3 ms 780 KB Output is correct
3 Correct 6 ms 1228 KB Output is correct
4 Correct 11 ms 2084 KB Output is correct
5 Correct 25 ms 3724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
19 Correct 70 ms 9112 KB Output is correct
20 Correct 68 ms 9048 KB Output is correct
21 Correct 67 ms 9116 KB Output is correct
22 Correct 66 ms 8944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
19 Correct 70 ms 9112 KB Output is correct
20 Correct 68 ms 9048 KB Output is correct
21 Correct 67 ms 9116 KB Output is correct
22 Correct 66 ms 8944 KB Output is correct
23 Correct 74 ms 9340 KB Output is correct
24 Correct 69 ms 9324 KB Output is correct
25 Correct 64 ms 9252 KB Output is correct
26 Correct 73 ms 9096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
19 Correct 70 ms 9112 KB Output is correct
20 Correct 68 ms 9048 KB Output is correct
21 Correct 67 ms 9116 KB Output is correct
22 Correct 66 ms 8944 KB Output is correct
23 Correct 74 ms 9340 KB Output is correct
24 Correct 69 ms 9324 KB Output is correct
25 Correct 64 ms 9252 KB Output is correct
26 Correct 73 ms 9096 KB Output is correct
27 Incorrect 74 ms 9636 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
19 Correct 70 ms 9112 KB Output is correct
20 Correct 68 ms 9048 KB Output is correct
21 Correct 67 ms 9116 KB Output is correct
22 Correct 66 ms 8944 KB Output is correct
23 Correct 74 ms 9340 KB Output is correct
24 Correct 69 ms 9324 KB Output is correct
25 Correct 64 ms 9252 KB Output is correct
26 Correct 73 ms 9096 KB Output is correct
27 Incorrect 74 ms 9636 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
6 Correct 3 ms 780 KB Output is correct
7 Correct 6 ms 1228 KB Output is correct
8 Correct 11 ms 2084 KB Output is correct
9 Correct 25 ms 3724 KB Output is correct
10 Correct 1 ms 544 KB Output is correct
11 Correct 14 ms 2596 KB Output is correct
12 Correct 23 ms 3748 KB Output is correct
13 Correct 22 ms 3752 KB Output is correct
14 Correct 22 ms 3624 KB Output is correct
15 Correct 75 ms 9060 KB Output is correct
16 Correct 75 ms 8976 KB Output is correct
17 Correct 74 ms 8800 KB Output is correct
18 Correct 63 ms 8728 KB Output is correct
19 Correct 70 ms 9112 KB Output is correct
20 Correct 68 ms 9048 KB Output is correct
21 Correct 67 ms 9116 KB Output is correct
22 Correct 66 ms 8944 KB Output is correct
23 Correct 74 ms 9340 KB Output is correct
24 Correct 69 ms 9324 KB Output is correct
25 Correct 64 ms 9252 KB Output is correct
26 Correct 73 ms 9096 KB Output is correct
27 Incorrect 74 ms 9636 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -