답안 #113792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
113792 2019-05-28T11:09:58 Z Mamnoon_Siam Minerals (JOI19_minerals) C++17
40 / 100
37 ms 4596 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;

void scattered(vector<int> u, vector<int> v) {
	assert(u.size() == v.size());
	if(u.empty()) return;
	if(u.size() == 1) {
		Answer(u.back(), v.back());
		return;
	}
	int mid = ((int)u.size() - 2) >> 1;
	int last;
	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(Query(u[i]) == last) {
			lu.emplace_back(u[i]);
		} else {
			ru.emplace_back(u[i]);
		}
		Query(u[i]);
	}
	for(int i = 0; i <= mid; i++) {
		Query(v[i]);
	}
	scattered(lu, lv);
	scattered(ru, rv);
}

void together(vector<int> v) {
	if(v.empty()) return;
	if(v.size() == 2) {
		Answer(v[0], v[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);
}

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>)':
minerals.cpp:18: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:57:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:64:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:77: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>)':
minerals.cpp:19:3: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(Query(u[i]) == last) {
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 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 3 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 10 ms 1024 KB Output is correct
5 Correct 19 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 2 ms 384 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 3 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 10 ms 1024 KB Output is correct
9 Correct 19 ms 1536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 15 ms 1512 KB Output is correct
12 Correct 23 ms 2144 KB Output is correct
13 Correct 26 ms 2884 KB Output is correct
14 Correct 15 ms 1584 KB Output is correct
15 Incorrect 37 ms 4596 KB Wrong Answer [2]
16 Halted 0 ms 0 KB -