# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51980 | diegogrc | Last supper (IOI12_supper) | C++17 | 0 ms | 0 KiB |
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 "advisor.h"
#define MAX 100005
#define INF 1e9
struct nodo
{
int v, p;
bool operator < ( const nodo & a ) const
{
return a.p > p;
}
};
bool activo[MAX];
int aparicion[MAX];
int sig[MAX];
int maxbits;
priority_queue < nodo > q;
void empuja( int x )
{
for( int i = maxbits - 1; i >= 0; i -- )
{
if( x & ( 1 << i ) )
WriteAdvice( 1 );
else
WriteAdvice( 0 );
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
maxbits = ( int ) ceil( log2( N ) );
for( int i = 0; i < N; i ++ )
aparicion[i] = INF;
for( int i = N-1; i >= 0; i -- )
{
sig[i] = aparicion[C[i]];
aparicion[C[i]] = i;
}
for( int i = 0; i < K; i ++ )
{
activo[i] = true;
q.push( { i , aparicion[i] } );
}
for( int i = 0; i < N; i ++ )
{
int val = C[i];
if( activo[val] )
empuja( val );
else
{
nodo act = q.top();
activo[act.v] = false;
q.pop();
empuja( act.v );
q.push( { val , sig[i] } );
activo[val] = true;
}
}
}
#include "assistant.h"
void Assist(unsigned char *A, int N, int K, int R) {
int numbits = ( int ) ceil( log2( N ) );
int idx = numbits - 1;
for( int i = 0; i < N; i ++ )
{
int color = GetRequest( );
int quita = 0;
for( int j = 0; j < numbits; j ++ )
if( A[idx - j] == 1 )
quita += ( 1 << j );
if( quita != color )
PutBack( quita );
idx += numbits;
}
}