# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376851 |
2021-03-12T05:33:47 Z |
8e7 |
Minerals (JOI19_minerals) |
C++14 |
|
52 ms |
3372 KB |
//Challenge: Accepted
#include "minerals.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#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:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | 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:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | 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 |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
3 ms |
492 KB |
Output is correct |
3 |
Correct |
5 ms |
620 KB |
Output is correct |
4 |
Correct |
9 ms |
1004 KB |
Output is correct |
5 |
Correct |
18 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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 KB |
Output is correct |
19 |
Incorrect |
52 ms |
3372 KB |
Wrong Answer [2] |
20 |
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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 KB |
Output is correct |
19 |
Incorrect |
52 ms |
3372 KB |
Wrong Answer [2] |
20 |
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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 KB |
Output is correct |
19 |
Incorrect |
52 ms |
3372 KB |
Wrong Answer [2] |
20 |
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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 KB |
Output is correct |
19 |
Incorrect |
52 ms |
3372 KB |
Wrong Answer [2] |
20 |
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 |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
620 KB |
Output is correct |
8 |
Correct |
9 ms |
1004 KB |
Output is correct |
9 |
Correct |
18 ms |
1388 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
12 ms |
1132 KB |
Output is correct |
12 |
Correct |
18 ms |
1388 KB |
Output is correct |
13 |
Correct |
20 ms |
1388 KB |
Output is correct |
14 |
Correct |
17 ms |
1388 KB |
Output is correct |
15 |
Correct |
52 ms |
3308 KB |
Output is correct |
16 |
Correct |
51 ms |
3180 KB |
Output is correct |
17 |
Correct |
46 ms |
3048 KB |
Output is correct |
18 |
Correct |
50 ms |
3016 KB |
Output is correct |
19 |
Incorrect |
52 ms |
3372 KB |
Wrong Answer [2] |
20 |
Halted |
0 ms |
0 KB |
- |