답안 #113878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113878 2019-05-29T02:10:31 Z Mamnoon_Siam Minerals (JOI19_minerals) C++17
100 / 100
104 ms 4672 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct RNG {
	int operator () (int n) {
		return rnd(n);
	}
};

void solve(vector<int> u, vector<int> v, int f) {
	if(u.empty()) return;

	if(u.size() == 1) {
		Answer(u.back(), v.back());
		return;
	}
	random_shuffle(u.begin(), u.end(), RNG());
	random_shuffle(v.begin(), v.end(), RNG());
	int mid, last;
	if(f) {
		// mid = ((int)u.size() + 1) >> 1;
		mid = 3 * u.size() / 5;
		if(mid == u.size()) mid--;
		for(int i = mid; i < v.size(); i++) {
			last = Query(v[i]);
		}
	} else {
		// mid = u.size() >> 1;
		mid = 2 * u.size() / 5;
		if(mid == 0) mid++;
		for(int i = 0; i < mid; i++) {
			last = Query(v[i]);
		}
	}
	vector<int> lu, lv(v.begin(), v.begin() + mid), ru, rv(v.begin() + mid, v.end());
	for(int i = 0; i < u.size(); i++) {
		if(lu.size() == lv.size()) {
			ru.emplace_back(u[i]);
		} else if(ru.size() == rv.size()) {
			lu.emplace_back(u[i]);
		} else {
			int rep = Query(u[i]);
			if(rep == last) {
				lu.emplace_back(u[i]);
			} else {
				ru.emplace_back(u[i]);
			}
			last = rep;
		}
	}
	solve(lu, lv, 1);
	solve(ru, rv, 0);
}

void split(vector<int> v) {
	random_shuffle(v.begin(), v.end(), RNG());
	vector<int> l, r;
	int last = -1;
	for(int i = 0; i < v.size(); i++) {
		if(r.size() == v.size() / 2) {
			l.emplace_back(v[i]);
			continue;
		}
		int rep = Query(v[i]);
		if(rep == last) {
			l.emplace_back(v[i]);
		} else {
			r.emplace_back(v[i]);
		} last = rep;
	}
	solve(l, r, 1);
}

void Solve(int N) {
	vector<int> v(2 * N);
	iota(v.begin(), v.end(), 1);
	split(v);
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:26:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(mid == u.size()) mid--;
      ~~~~^~~~~~~~~~~
minerals.cpp:27:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = mid; i < v.size(); i++) {
                    ~~^~~~~~~~~~
minerals.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void split(std::vector<int>)':
minerals.cpp:62:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, int)':
minerals.cpp:46:4: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(rep == last) {
    ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 9 ms 640 KB Output is correct
4 Correct 16 ms 1024 KB Output is correct
5 Correct 30 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
19 Correct 80 ms 4084 KB Output is correct
20 Correct 82 ms 4084 KB Output is correct
21 Correct 80 ms 4212 KB Output is correct
22 Correct 80 ms 3928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
19 Correct 80 ms 4084 KB Output is correct
20 Correct 82 ms 4084 KB Output is correct
21 Correct 80 ms 4212 KB Output is correct
22 Correct 80 ms 3928 KB Output is correct
23 Correct 84 ms 4084 KB Output is correct
24 Correct 83 ms 4212 KB Output is correct
25 Correct 81 ms 4092 KB Output is correct
26 Correct 81 ms 4028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
19 Correct 80 ms 4084 KB Output is correct
20 Correct 82 ms 4084 KB Output is correct
21 Correct 80 ms 4212 KB Output is correct
22 Correct 80 ms 3928 KB Output is correct
23 Correct 84 ms 4084 KB Output is correct
24 Correct 83 ms 4212 KB Output is correct
25 Correct 81 ms 4092 KB Output is correct
26 Correct 81 ms 4028 KB Output is correct
27 Correct 91 ms 4360 KB Output is correct
28 Correct 86 ms 4340 KB Output is correct
29 Correct 88 ms 4340 KB Output is correct
30 Correct 82 ms 4084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
19 Correct 80 ms 4084 KB Output is correct
20 Correct 82 ms 4084 KB Output is correct
21 Correct 80 ms 4212 KB Output is correct
22 Correct 80 ms 3928 KB Output is correct
23 Correct 84 ms 4084 KB Output is correct
24 Correct 83 ms 4212 KB Output is correct
25 Correct 81 ms 4092 KB Output is correct
26 Correct 81 ms 4028 KB Output is correct
27 Correct 91 ms 4360 KB Output is correct
28 Correct 86 ms 4340 KB Output is correct
29 Correct 88 ms 4340 KB Output is correct
30 Correct 82 ms 4084 KB Output is correct
31 Correct 92 ms 4672 KB Output is correct
32 Correct 96 ms 4428 KB Output is correct
33 Correct 94 ms 4264 KB Output is correct
34 Correct 92 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 384 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 9 ms 640 KB Output is correct
8 Correct 16 ms 1024 KB Output is correct
9 Correct 30 ms 1792 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 19 ms 1280 KB Output is correct
12 Correct 30 ms 1664 KB Output is correct
13 Correct 28 ms 1792 KB Output is correct
14 Correct 28 ms 1664 KB Output is correct
15 Correct 80 ms 3956 KB Output is correct
16 Correct 79 ms 4084 KB Output is correct
17 Correct 78 ms 3956 KB Output is correct
18 Correct 76 ms 3836 KB Output is correct
19 Correct 80 ms 4084 KB Output is correct
20 Correct 82 ms 4084 KB Output is correct
21 Correct 80 ms 4212 KB Output is correct
22 Correct 80 ms 3928 KB Output is correct
23 Correct 84 ms 4084 KB Output is correct
24 Correct 83 ms 4212 KB Output is correct
25 Correct 81 ms 4092 KB Output is correct
26 Correct 81 ms 4028 KB Output is correct
27 Correct 91 ms 4360 KB Output is correct
28 Correct 86 ms 4340 KB Output is correct
29 Correct 88 ms 4340 KB Output is correct
30 Correct 82 ms 4084 KB Output is correct
31 Correct 92 ms 4672 KB Output is correct
32 Correct 96 ms 4428 KB Output is correct
33 Correct 94 ms 4264 KB Output is correct
34 Correct 92 ms 4216 KB Output is correct
35 Correct 95 ms 4388 KB Output is correct
36 Correct 104 ms 4452 KB Output is correct
37 Correct 96 ms 4468 KB Output is correct
38 Correct 95 ms 4212 KB Output is correct