답안 #113821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113821 2019-05-28T14:05:18 Z Mamnoon_Siam Minerals (JOI19_minerals) C++17
75 / 100
132 ms 5428 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) {
	assert(u.size() == v.size());
	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());
	
	if(v.empty()) return;
	if(v.size() == 2) return Answer(v[0], v[1]);
	if(v.size() == 4) {
		int last = Query(v[0]);
		int with = -1;
		if(Query(v[1]) == last) with = 1;
		else Query(v[1]);
		if(with == -1) {
			if(Query(v[2]) == last) with = 2;
			else with = 3;
		}
		vector<int> tmp;
		for(int i : {1, 2, 3})
			if(i != with) tmp.emplace_back(v[i]);
		Answer(v[0], v[with]);
		Answer(tmp[0], tmp[1]);
		return;
	}

	int mid = ((int)v.size()) / 2 - 1;

	vector<int> l, r, dl, dr;
	int last = 0;
	for(int i = 0; i <= mid; i++) {
		int rep = Query(v[i]);
		if(rep == last) {
			l.emplace_back(v[i]);
		}
		last = rep;
	}
	for(int i = 0; i <= mid; i++) {
		int rep = Query(v[i]);
		if(rep == last) {
			l.emplace_back(v[i]);
		}
		last = rep;
	}
	last = 0;
	for(int i = mid + 1; i < v.size(); i++) {
		int rep = Query(v[i]);
		if(rep == last) {
			r.emplace_back(v[i]);
		}
		last = rep;
	}
	for(int i = mid + 1; i < v.size(); i++) {
		int rep = Query(v[i]);
		if(rep == last) {
			r.emplace_back(v[i]);
		}
		last = rep;
	}
	set<int> sl(l.begin(), l.end()), sr(r.begin(), r.end());
	for(int i = 0; i <= mid; i++) {
		if(sl.find(v[i]) == sl.end()) {
			dl.emplace_back(v[i]);
		}
	}
	for(int i = mid + 1; i < v.size(); i++) {
		if(sr.find(v[i]) == sr.end()) {
			dr.emplace_back(v[i]);
		}
	}
	together(l);
	together(r);
	scattered(dl, dr, 0);
}

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:26:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = mid + 1; i < v.size(); i++) {
                        ~~^~~~~~~~~~
minerals.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void together(std::vector<int>)':
minerals.cpp:95:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:102:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:115:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp: In function 'void scattered(std::vector<int>, std::vector<int>, int)':
minerals.cpp:42: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 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 412 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 10 ms 768 KB Output is correct
4 Correct 19 ms 1280 KB Output is correct
5 Correct 38 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
19 Correct 132 ms 5272 KB Output is correct
20 Correct 132 ms 5140 KB Output is correct
21 Correct 114 ms 5268 KB Output is correct
22 Correct 121 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
19 Correct 132 ms 5272 KB Output is correct
20 Correct 132 ms 5140 KB Output is correct
21 Correct 114 ms 5268 KB Output is correct
22 Correct 121 ms 4984 KB Output is correct
23 Incorrect 125 ms 5428 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
19 Correct 132 ms 5272 KB Output is correct
20 Correct 132 ms 5140 KB Output is correct
21 Correct 114 ms 5268 KB Output is correct
22 Correct 121 ms 4984 KB Output is correct
23 Incorrect 125 ms 5428 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
19 Correct 132 ms 5272 KB Output is correct
20 Correct 132 ms 5140 KB Output is correct
21 Correct 114 ms 5268 KB Output is correct
22 Correct 121 ms 4984 KB Output is correct
23 Incorrect 125 ms 5428 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 384 KB Output is correct
5 Correct 3 ms 412 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 10 ms 768 KB Output is correct
8 Correct 19 ms 1280 KB Output is correct
9 Correct 38 ms 2176 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 25 ms 1536 KB Output is correct
12 Correct 40 ms 2176 KB Output is correct
13 Correct 40 ms 2304 KB Output is correct
14 Correct 38 ms 2204 KB Output is correct
15 Correct 118 ms 5020 KB Output is correct
16 Correct 124 ms 5036 KB Output is correct
17 Correct 119 ms 5040 KB Output is correct
18 Correct 120 ms 4904 KB Output is correct
19 Correct 132 ms 5272 KB Output is correct
20 Correct 132 ms 5140 KB Output is correct
21 Correct 114 ms 5268 KB Output is correct
22 Correct 121 ms 4984 KB Output is correct
23 Incorrect 125 ms 5428 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -