#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 43000;
int pairr[2 * MAX_N + 1], perm[2 * MAX_N + 1];
bool inSet[2 * MAX_N + 1];
vector<int> firstt, secondd;
int ans = 0;
void solve( vector <int> &f, vector<int> &s ) {
if ( f.size() == 1 && s.size() == 1 ) {
pairr[s[0]] = f[0];
return;
}
vector<int> fl, fr, sl, sr;
int lis, ris;
for ( int i = 0; i < f.size() / 2; i++ )
lis += inSet[i];
for ( int i = f.size() / 2; i < f.size(); i++ )
ris += inSet[i];
if ( lis < ris ) {
for ( int i = 0; i < f.size() / 2; i++ )
swap( f[i], f[i + f.size() / 2] );
}
int leftt = 0, rightt = 0;
for ( int i = 0; i < f.size() / 2; i++ ) {
if ( !inSet[f[i]] ) {
ans = Query( f[i] );
inSet[f[i]] = true;
}
fl.push_back( f[i] );
leftt++;
}
for ( int i = f.size() / 2; i < f.size(); i++ ) {
if ( inSet[f[i]] ) {
ans = Query( f[i] );
inSet[f[i]] = false;
}
fr.push_back( f[i] );
rightt++;
}
random_shuffle( s.begin(), s.end() );
for ( int i = 0; i < s.size(); i++ ) {
if ( rightt == 0 ) {
sl.push_back( s[i] );
leftt--;
continue;
}
if ( leftt == 0 ) {
sr.push_back( s[i] );
rightt--;
continue;
}
int prevAns = ans;
ans = Query( s[i] );
inSet[s[i]] ^= 1;
if ( ans == prevAns ) {
sl.push_back( s[i] );
leftt--;
} else {
sr.push_back( s[i] );
rightt--;
}
}
solve( fl, sl );
solve( fr, sr );
}
void Solve( int n ) {
for ( int i = 1; i <= 2 * n; i++ )
perm[i] = i;
random_shuffle( perm + 1, perm + 1 + 2 * n );
int prevAns = 0;
for ( int i = 1; i <= 2 * n; i++ ) {
if ( firstt.size() == n ) {
secondd.push_back( perm[i] );
continue;
}
ans = Query( perm[i] );
inSet[perm[i]] = true;
if ( ans > prevAns )
firstt.push_back( perm[i] );
else
secondd.push_back( perm[i] );
prevAns = ans;
}
random_shuffle( firstt.begin(), firstt.end() );
random_shuffle( secondd.begin(), secondd.end() );
solve( firstt, secondd );
for ( int i = 0; i < n; i++ )
Answer( secondd[i], pairr[secondd[i]] );
}
Compilation message
minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&)':
minerals.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for ( int i = 0; i < f.size() / 2; i++ )
| ~~^~~~~~~~~~~~~~
minerals.cpp:23:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for ( int i = f.size() / 2; i < f.size(); i++ )
| ~~^~~~~~~~~~
minerals.cpp:26:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for ( int i = 0; i < f.size() / 2; i++ )
| ~~^~~~~~~~~~~~~~
minerals.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for ( int i = 0; i < f.size() / 2; i++ ) {
| ~~^~~~~~~~~~~~~~
minerals.cpp:39:35: 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 = f.size() / 2; i < f.size(); i++ ) {
| ~~^~~~~~~~~~
minerals.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for ( int i = 0; i < s.size(); i++ ) {
| ~~^~~~~~~~~~
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:84:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
84 | if ( firstt.size() == n ) {
| ~~~~~~~~~~~~~~^~~~
minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&)':
minerals.cpp:25:5: warning: 'ris' may be used uninitialized in this function [-Wmaybe-uninitialized]
25 | if ( lis < ris ) {
| ^~
minerals.cpp:25:5: warning: 'lis' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
4 ms |
856 KB |
Output is correct |
4 |
Correct |
7 ms |
1120 KB |
Output is correct |
5 |
Correct |
13 ms |
1368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
19 |
Correct |
42 ms |
3412 KB |
Output is correct |
20 |
Correct |
39 ms |
3408 KB |
Output is correct |
21 |
Correct |
37 ms |
3416 KB |
Output is correct |
22 |
Correct |
37 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
19 |
Correct |
42 ms |
3412 KB |
Output is correct |
20 |
Correct |
39 ms |
3408 KB |
Output is correct |
21 |
Correct |
37 ms |
3416 KB |
Output is correct |
22 |
Correct |
37 ms |
3148 KB |
Output is correct |
23 |
Correct |
40 ms |
3488 KB |
Output is correct |
24 |
Correct |
40 ms |
3280 KB |
Output is correct |
25 |
Correct |
38 ms |
3304 KB |
Output is correct |
26 |
Correct |
39 ms |
3364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
19 |
Correct |
42 ms |
3412 KB |
Output is correct |
20 |
Correct |
39 ms |
3408 KB |
Output is correct |
21 |
Correct |
37 ms |
3416 KB |
Output is correct |
22 |
Correct |
37 ms |
3148 KB |
Output is correct |
23 |
Correct |
40 ms |
3488 KB |
Output is correct |
24 |
Correct |
40 ms |
3280 KB |
Output is correct |
25 |
Correct |
38 ms |
3304 KB |
Output is correct |
26 |
Correct |
39 ms |
3364 KB |
Output is correct |
27 |
Correct |
42 ms |
3568 KB |
Output is correct |
28 |
Correct |
41 ms |
3576 KB |
Output is correct |
29 |
Correct |
39 ms |
3560 KB |
Output is correct |
30 |
Correct |
40 ms |
3564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
19 |
Correct |
42 ms |
3412 KB |
Output is correct |
20 |
Correct |
39 ms |
3408 KB |
Output is correct |
21 |
Correct |
37 ms |
3416 KB |
Output is correct |
22 |
Correct |
37 ms |
3148 KB |
Output is correct |
23 |
Correct |
40 ms |
3488 KB |
Output is correct |
24 |
Correct |
40 ms |
3280 KB |
Output is correct |
25 |
Correct |
38 ms |
3304 KB |
Output is correct |
26 |
Correct |
39 ms |
3364 KB |
Output is correct |
27 |
Correct |
42 ms |
3568 KB |
Output is correct |
28 |
Correct |
41 ms |
3576 KB |
Output is correct |
29 |
Correct |
39 ms |
3560 KB |
Output is correct |
30 |
Correct |
40 ms |
3564 KB |
Output is correct |
31 |
Correct |
44 ms |
3572 KB |
Output is correct |
32 |
Correct |
41 ms |
3572 KB |
Output is correct |
33 |
Correct |
40 ms |
3508 KB |
Output is correct |
34 |
Correct |
45 ms |
3384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
856 KB |
Output is correct |
8 |
Correct |
7 ms |
1120 KB |
Output is correct |
9 |
Correct |
13 ms |
1368 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
9 ms |
1028 KB |
Output is correct |
12 |
Correct |
15 ms |
1596 KB |
Output is correct |
13 |
Correct |
19 ms |
1368 KB |
Output is correct |
14 |
Correct |
19 ms |
1512 KB |
Output is correct |
15 |
Correct |
37 ms |
3288 KB |
Output is correct |
16 |
Correct |
37 ms |
3408 KB |
Output is correct |
17 |
Correct |
41 ms |
3320 KB |
Output is correct |
18 |
Correct |
52 ms |
3400 KB |
Output is correct |
19 |
Correct |
42 ms |
3412 KB |
Output is correct |
20 |
Correct |
39 ms |
3408 KB |
Output is correct |
21 |
Correct |
37 ms |
3416 KB |
Output is correct |
22 |
Correct |
37 ms |
3148 KB |
Output is correct |
23 |
Correct |
40 ms |
3488 KB |
Output is correct |
24 |
Correct |
40 ms |
3280 KB |
Output is correct |
25 |
Correct |
38 ms |
3304 KB |
Output is correct |
26 |
Correct |
39 ms |
3364 KB |
Output is correct |
27 |
Correct |
42 ms |
3568 KB |
Output is correct |
28 |
Correct |
41 ms |
3576 KB |
Output is correct |
29 |
Correct |
39 ms |
3560 KB |
Output is correct |
30 |
Correct |
40 ms |
3564 KB |
Output is correct |
31 |
Correct |
44 ms |
3572 KB |
Output is correct |
32 |
Correct |
41 ms |
3572 KB |
Output is correct |
33 |
Correct |
40 ms |
3508 KB |
Output is correct |
34 |
Correct |
45 ms |
3384 KB |
Output is correct |
35 |
Incorrect |
44 ms |
3444 KB |
Wrong Answer [2] |
36 |
Halted |
0 ms |
0 KB |
- |