# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376860 |
2021-03-12T05:47:04 Z |
8e7 |
Minerals (JOI19_minerals) |
C++14 |
|
61 ms |
3456 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 solve2(vector<int> a, vector<int> b, bool type) { //type is true if add, false if del
int num = Query(a[0]);
bool res = (Query(b[0]) == num) ^ type;
if (res) {
Answer(a[1], b[0]);
Answer(a[0], b[1]);
} else {
Answer(a[0], b[0]);
Answer(a[1], b[1]);
}
}
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;
}
if (a.size() == 2) {
/*
int num = Query(a[0]);
if (Query(b[0]) == num) {
Answer(a[1], b[0]);
Answer(a[0], b[1]);
} else {
Answer(a[0], b[0]);
Answer(a[1], b[1]);
}
*/
solve2(a, b, false);
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;
}
if (a.size() == 2) {
solve2(a, b, true);
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;
}
if (a.size() == 2) {
solve2(a, b, false);
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) {
Answer(a[0], b[0]);
return;
}
if (a.size() == 2) {
solve2(a, b, true);
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++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
4 ms |
620 KB |
Output is correct |
4 |
Correct |
8 ms |
876 KB |
Output is correct |
5 |
Correct |
18 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
19 |
Correct |
48 ms |
3456 KB |
Output is correct |
20 |
Correct |
46 ms |
3308 KB |
Output is correct |
21 |
Correct |
38 ms |
3176 KB |
Output is correct |
22 |
Correct |
38 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
19 |
Correct |
48 ms |
3456 KB |
Output is correct |
20 |
Correct |
46 ms |
3308 KB |
Output is correct |
21 |
Correct |
38 ms |
3176 KB |
Output is correct |
22 |
Correct |
38 ms |
3052 KB |
Output is correct |
23 |
Correct |
48 ms |
3308 KB |
Output is correct |
24 |
Correct |
61 ms |
3456 KB |
Output is correct |
25 |
Correct |
48 ms |
3176 KB |
Output is correct |
26 |
Correct |
47 ms |
3052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
19 |
Correct |
48 ms |
3456 KB |
Output is correct |
20 |
Correct |
46 ms |
3308 KB |
Output is correct |
21 |
Correct |
38 ms |
3176 KB |
Output is correct |
22 |
Correct |
38 ms |
3052 KB |
Output is correct |
23 |
Correct |
48 ms |
3308 KB |
Output is correct |
24 |
Correct |
61 ms |
3456 KB |
Output is correct |
25 |
Correct |
48 ms |
3176 KB |
Output is correct |
26 |
Correct |
47 ms |
3052 KB |
Output is correct |
27 |
Incorrect |
52 ms |
3408 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
19 |
Correct |
48 ms |
3456 KB |
Output is correct |
20 |
Correct |
46 ms |
3308 KB |
Output is correct |
21 |
Correct |
38 ms |
3176 KB |
Output is correct |
22 |
Correct |
38 ms |
3052 KB |
Output is correct |
23 |
Correct |
48 ms |
3308 KB |
Output is correct |
24 |
Correct |
61 ms |
3456 KB |
Output is correct |
25 |
Correct |
48 ms |
3176 KB |
Output is correct |
26 |
Correct |
47 ms |
3052 KB |
Output is correct |
27 |
Incorrect |
52 ms |
3408 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
620 KB |
Output is correct |
8 |
Correct |
8 ms |
876 KB |
Output is correct |
9 |
Correct |
18 ms |
1516 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1096 KB |
Output is correct |
12 |
Correct |
21 ms |
1388 KB |
Output is correct |
13 |
Correct |
14 ms |
1436 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
44 ms |
3180 KB |
Output is correct |
16 |
Correct |
48 ms |
3308 KB |
Output is correct |
17 |
Correct |
37 ms |
2976 KB |
Output is correct |
18 |
Correct |
44 ms |
2924 KB |
Output is correct |
19 |
Correct |
48 ms |
3456 KB |
Output is correct |
20 |
Correct |
46 ms |
3308 KB |
Output is correct |
21 |
Correct |
38 ms |
3176 KB |
Output is correct |
22 |
Correct |
38 ms |
3052 KB |
Output is correct |
23 |
Correct |
48 ms |
3308 KB |
Output is correct |
24 |
Correct |
61 ms |
3456 KB |
Output is correct |
25 |
Correct |
48 ms |
3176 KB |
Output is correct |
26 |
Correct |
47 ms |
3052 KB |
Output is correct |
27 |
Incorrect |
52 ms |
3408 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |