This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 43000;
const int UNDEF = -1;
int pairr[2 * MAX_N + 1], perm[2 * MAX_N + 1];
bool isFirst[2 * MAX_N + 1];
int ans = 0;
void solve( vector <int> &v, bool active ) {
int n = v.size() / 2, ln = n / 2;
vector<int> left, right;
/*printf( "%d %d: ", n, active );
for ( int i: v )
printf( "%d ", perm[i] );
printf( "\n" );*/
if ( n == 1 ) {
pairr[v[0]] = v[1];
pairr[v[1]] = v[0];
return;
}
int pairs = 0;
int q = 0;
for ( int i: v ) {
if ( isFirst[i] ) {
if ( pairs == ln )
right.push_back( i );
else {
left.push_back( i );
pairs++;
ans = Query( perm[i] );
q++;
}
} else {
if ( left.size() == 2 * ln )
right.push_back( i );
else if ( pairs < ln ) {
left.push_back( i );
ans = Query( perm[i] );
q++;
} else {
int prevAns = ans;
ans = Query( perm[i] );
q++;
if ( (!active && ans == prevAns) || (active && ans < prevAns) )
left.push_back( i );
else {
ans = Query( perm[i] );
q++;
right.push_back( i );
}
}
}
}
//printf( "%d %d\n", n, q );
solve( left, !active );
solve( right, active );
}
void Solve( int n ) {
vector<int> v;
for ( int i = 1; i <= 2 * n; i++ ) {
pairr[i] = UNDEF;
v.push_back( i );
perm[i] = i;
}
random_shuffle( perm + 1, perm + 1 + 2 * n );
int prevAns = 0;
for ( int i = 1; i <= 2 * n; i++ ) {
ans = Query( perm[i] );
isFirst[i] = (ans > prevAns);
prevAns = ans;
}
solve( v, true );
for ( int i = 1; i <= 2 * n; i++ ) {
if ( pairr[i] < i )
Answer( perm[i], perm[pairr[i]] );
}
}
Compilation message (stderr)
minerals.cpp: In function 'void solve(std::vector<int>&, bool)':
minerals.cpp:40:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if ( left.size() == 2 * ln )
| ~~~~~~~~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |