답안 #376856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376856 2021-03-12T05:37:33 Z 8e7 Minerals (JOI19_minerals) C++14
75 / 100
54 ms 3436 KB
//Challenge: Accepted
#include "minerals.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <random>
#include <time.h>
#define ll long long
#define maxn 100005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int tot;
void solvewitha(vector<int> a, vector<int> b); //if there is still a
void solvewithb(vector<int> a, vector<int> b); //if there is still b
void solvebydel(vector<int> a, vector<int> b);
void solvebyadd(vector<int> a, vector<int> b);

void Solve(int N) {
	tot = N;
	int num = 0;
	vector<int> l, r;
	for (int i = 1;i <= 2 * N;i++) {
		int tmp = Query(i);
		if (tmp != num) l.push_back(i);
		else r.push_back(i);
		num = tmp;
	}
	//for (int i = 1;i <= 2 * N;i++) Query(i);
	solvebydel(l, r);
}

void adda(int & num, int mid, vector<int> &a, vector<int> & al, vector<int> &ar) {
	for (int i = 0;i < mid;i++) {
		num = Query(a[i]);
		al.push_back(a[i]);
	}
	for (int i = mid;i < a.size();i++) ar.push_back(a[i]);
}
void addb(int &num, vector<int> &b, vector<int> &bl, vector<int> &br, bool type) {
	//true if left of a is there, false otherwise
	for (int i = 0;i < b.size();i++) {
		int tmp = Query(b[i]);
		if ((tmp == num) == type) {
			bl.push_back(b[i]);
		} else {
			br.push_back(b[i]);
		}
		num = tmp;
	}
}

void solvewitha(vector<int> a, vector<int> b) {
	if (a.size() < 1) return;
	if (a.size() == 1) {
		//Query(a[0]);
		Answer(a[0], b[0]);
		return;
	}
	vector<int> al, bl, ar, br;
	int num = 0, mid = (a.size() + 1) / 2;
	adda(num, mid, a, al, ar);
	addb(num, b, bl, br, false);
	solvewithb(al, bl);
	solvebydel(ar, br);
}
void solvewithb(vector<int> a, vector<int> b) {
	if (a.size() < 1) return;
	if (a.size() == 1) {
		//Query(b[0]);
		Answer(a[0], b[0]);
		return;
	}
	vector<int> al, bl, ar, br;
	int num = 0, mid = (a.size() + 1) / 2;
	adda(num, mid, a, al, ar);
	addb(num, b, bl, br, true);
	solvewitha(al, bl);
	solvebyadd(ar, br);
}

void solvebydel(vector<int> a, vector<int> b) {
	if (a.size() < 1) return;

	if (a.size() == 1) { //look here
		//Query(a[0]), Query(b[0]);
		Answer(a[0], b[0]);
		return;
	}

	vector<int> al, bl, ar, br;
	int num = 0, mid = (a.size() + 1) / 2;
	adda(num, mid, a, al, ar);
	addb(num, b, bl, br, false);

	solvebyadd(al, bl);
	solvewitha(ar, br);
}

void solvebyadd(vector<int> a, vector<int> b) {
	if (a.size() < 1) return;

	if (a.size() == 1) { //look here
		Answer(a[0], b[0]);
		return;
	}

	vector<int> al, bl, ar, br;
	int num = 0, mid = (a.size() + 1) / 2;
	adda(num, mid, a, al, ar);
	addb(num, b, bl, br, true);

	solvebydel(al, bl);
	solvewithb(ar, br);
}
/*
4
1 5
2 6
3 4
7 8

 */

Compilation message

minerals.cpp: In function 'void adda(int&, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
minerals.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = mid;i < a.size();i++) ar.push_back(a[i]);
      |                   ~~^~~~~~~~~~
minerals.cpp: In function 'void addb(int&, std::vector<int>&, std::vector<int>&, std::vector<int>&, bool)':
minerals.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i = 0;i < b.size();i++) {
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 9 ms 876 KB Output is correct
5 Correct 18 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
19 Correct 52 ms 3308 KB Output is correct
20 Correct 52 ms 3308 KB Output is correct
21 Correct 41 ms 3176 KB Output is correct
22 Correct 43 ms 3052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
19 Correct 52 ms 3308 KB Output is correct
20 Correct 52 ms 3308 KB Output is correct
21 Correct 41 ms 3176 KB Output is correct
22 Correct 43 ms 3052 KB Output is correct
23 Incorrect 53 ms 3436 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
19 Correct 52 ms 3308 KB Output is correct
20 Correct 52 ms 3308 KB Output is correct
21 Correct 41 ms 3176 KB Output is correct
22 Correct 43 ms 3052 KB Output is correct
23 Incorrect 53 ms 3436 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
19 Correct 52 ms 3308 KB Output is correct
20 Correct 52 ms 3308 KB Output is correct
21 Correct 41 ms 3176 KB Output is correct
22 Correct 43 ms 3052 KB Output is correct
23 Incorrect 53 ms 3436 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 3 ms 640 KB Output is correct
7 Correct 4 ms 620 KB Output is correct
8 Correct 9 ms 876 KB Output is correct
9 Correct 18 ms 1388 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 15 ms 1132 KB Output is correct
12 Correct 23 ms 1388 KB Output is correct
13 Correct 17 ms 1388 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 54 ms 3180 KB Output is correct
16 Correct 53 ms 3180 KB Output is correct
17 Correct 46 ms 3064 KB Output is correct
18 Correct 41 ms 3052 KB Output is correct
19 Correct 52 ms 3308 KB Output is correct
20 Correct 52 ms 3308 KB Output is correct
21 Correct 41 ms 3176 KB Output is correct
22 Correct 43 ms 3052 KB Output is correct
23 Incorrect 53 ms 3436 KB Wrong Answer [2]
24 Halted 0 ms 0 KB -