Submission #113871

# Submission time Handle Problem Language Result Execution time Memory
113871 2019-05-29T01:18:12 Z Mamnoon_Siam Minerals (JOI19_minerals) C++17
80 / 100
84 ms 3956 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 scattered(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 = ((int)u.size() - 2) >> 1;
	int last;
	if(f) {
		for(int i = mid + 1; i < v.size(); i++) {
			last = Query(v[i]);
		}
	} else {
		for(int i = 0; i <= mid; i++) {
			last = Query(v[i]);
		}
	}
	vector<int> lu, lv(v.begin(), v.begin() + mid + 1), ru, rv(v.begin() + mid + 1, 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;
		}
	}
	scattered(lu, lv, 1);
	scattered(ru, rv, 0);
}

void together(vector<int> v) {
	random_shuffle(v.begin(), v.end(), RNG());
	// random_shuffle(v.begin(), v.end(), RNG());

	if(v.empty()) return;
	if(v.size() == 2) return Answer(v[0], v[1]);
	if(v.size() == 4) {
		int last = Query(v[0]);
		if(Query(v[1]) == last) {
			together({v[0], v[1]});
			together({v[2], v[3]});
			return;
		} else {
			scattered({v[2], v[3]}, {v[0], v[1]}, 1);
		}
		return;
	}
	vector<int> l, r;
	int last = -1;
	for(int i = 0; i < (int)v.size() - 1; i++) {
		int rep = Query(v[i]);
		if(rep == last) {
			l.emplace_back(v[i]);
			last = Query(v[i]);
		} else {
			r.emplace_back(v[i]);
			last = rep;
		}
	}
	l.emplace_back(v.back());
	scattered(l, r, 1);
}

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

Compilation message

minerals.cpp: In function 'void scattered(std::vector<int>, std::vector<int>, int)':
minerals.cpp:25:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = mid + 1; i < v.size(); i++) {
                        ~~^~~~~~~~~~
minerals.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp:41:4: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(rep == last) {
    ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 7 ms 640 KB Output is correct
4 Correct 14 ms 896 KB Output is correct
5 Correct 27 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
19 Correct 84 ms 3752 KB Output is correct
20 Correct 78 ms 3840 KB Output is correct
21 Correct 78 ms 3884 KB Output is correct
22 Correct 77 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
19 Correct 84 ms 3752 KB Output is correct
20 Correct 78 ms 3840 KB Output is correct
21 Correct 78 ms 3884 KB Output is correct
22 Correct 77 ms 3708 KB Output is correct
23 Correct 80 ms 3952 KB Output is correct
24 Correct 83 ms 3896 KB Output is correct
25 Correct 80 ms 3956 KB Output is correct
26 Correct 79 ms 3780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
19 Correct 84 ms 3752 KB Output is correct
20 Correct 78 ms 3840 KB Output is correct
21 Correct 78 ms 3884 KB Output is correct
22 Correct 77 ms 3708 KB Output is correct
23 Correct 80 ms 3952 KB Output is correct
24 Correct 83 ms 3896 KB Output is correct
25 Correct 80 ms 3956 KB Output is correct
26 Correct 79 ms 3780 KB Output is correct
27 Incorrect 81 ms 3888 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
19 Correct 84 ms 3752 KB Output is correct
20 Correct 78 ms 3840 KB Output is correct
21 Correct 78 ms 3884 KB Output is correct
22 Correct 77 ms 3708 KB Output is correct
23 Correct 80 ms 3952 KB Output is correct
24 Correct 83 ms 3896 KB Output is correct
25 Correct 80 ms 3956 KB Output is correct
26 Correct 79 ms 3780 KB Output is correct
27 Incorrect 81 ms 3888 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 7 ms 640 KB Output is correct
8 Correct 14 ms 896 KB Output is correct
9 Correct 27 ms 1536 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 18 ms 1180 KB Output is correct
12 Correct 28 ms 1636 KB Output is correct
13 Correct 27 ms 1664 KB Output is correct
14 Correct 27 ms 1592 KB Output is correct
15 Correct 78 ms 3744 KB Output is correct
16 Correct 78 ms 3700 KB Output is correct
17 Correct 76 ms 3712 KB Output is correct
18 Correct 77 ms 3580 KB Output is correct
19 Correct 84 ms 3752 KB Output is correct
20 Correct 78 ms 3840 KB Output is correct
21 Correct 78 ms 3884 KB Output is correct
22 Correct 77 ms 3708 KB Output is correct
23 Correct 80 ms 3952 KB Output is correct
24 Correct 83 ms 3896 KB Output is correct
25 Correct 80 ms 3956 KB Output is correct
26 Correct 79 ms 3780 KB Output is correct
27 Incorrect 81 ms 3888 KB Wrong Answer [2]
28 Halted 0 ms 0 KB -