#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <exception>
#include <numeric>
#include <string>
#include <utility>
#include <variant>
#include <vector>
#include "messy.h"
using namespace std;
#ifndef LOCAL
#define cerr if( false ) cerr
#endif
#define out(x) #x << " = " << x << " "
int n;
void ask( int l, int r ){
if( l == r ) return;
int m = ( l + r ) >> 1;
std::string base = "";
for( int i=0 ; i < n ; i ++ ){
if( i < l || i > r ) base += "1";
else base += "0";
}
for( int i=l ; i <= m ; i++ ){
std::string curr = base;
curr[i] = '1';
cerr << " ? " << out( curr ) << endl;
add_element( curr );
}
ask( l, m );
ask( m+1, r );
}
std::vector< int > nas;
void solve( int l, int r, const std::vector< int >& posInd ){
cerr << out( l ) << out( r ) << endl;
for( auto j : posInd ) cerr << j << " ";
cerr << endl;
if( l == r ){
nas[ posInd[0] ] = l;
return;
}
int m = ( l + r ) >> 1;
std::string base = "";
for( int i=0 ; i < n ; i++ ) base += "1";
for( auto j : posInd ) base[j] = '0';
cerr << out( base ) << endl;
std::vector< int > left;
std::vector< int > right;
for( auto j : posInd ){
std::string curr = base;
curr[j] = '1';
cerr << " ! " << out( curr ) << endl;
if( check_element( curr ) ) left.push_back( j );
else right.push_back( j );
}
solve( l, m, left );
solve( m+1, r, right );
}
std::vector<int> restore_permutation(int N, int w, int r) {
n = N;
nas.resize( n );
ask( 0, n-1 );
compile_set();
std::vector< int > posInd( n );
std::iota( posInd.begin(), posInd.end(), 0 );
solve( 0, n-1, posInd );
//std::cout << N << " " << w << " " << r << endl;
return nas;
}
Compilation message (stderr)
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |