#include "advisor.h"
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define INF 1e9
struct nodo
{
int v, p;
bool operator < ( const nodo & a ) const
{
if( a.p != p )
return a.p > p;
return a.v < v;
}
};
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 -- )
{
int val = C[i];
sig[i] = aparicion[val];
aparicion[val] = 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 );
q.push( { val , sig[i] } );
}
else
{
while( q.top().p < i )
q.pop();
nodo act = q.top();
activo[act.v] = false;
q.pop();
empuja( act.v );
q.push( { val , sig[i] } );
activo[val] = true;
}
}
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
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;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
608 KB |
Output is correct |
2 |
Correct |
4 ms |
952 KB |
Output is correct |
3 |
Correct |
6 ms |
1080 KB |
Output is correct |
4 |
Correct |
13 ms |
1304 KB |
Output is correct |
5 |
Correct |
24 ms |
1624 KB |
Output is correct |
6 |
Correct |
19 ms |
1656 KB |
Output is correct |
7 |
Correct |
19 ms |
1840 KB |
Output is correct |
8 |
Correct |
19 ms |
1840 KB |
Output is correct |
9 |
Correct |
19 ms |
1840 KB |
Output is correct |
10 |
Correct |
22 ms |
1840 KB |
Output is correct |
11 |
Correct |
23 ms |
1840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
2608 KB |
Output is correct |
2 |
Correct |
207 ms |
8488 KB |
Output is correct |
3 |
Correct |
466 ms |
16560 KB |
Output is correct |
4 |
Correct |
406 ms |
16560 KB |
Output is correct |
5 |
Correct |
427 ms |
16560 KB |
Output is correct |
6 |
Correct |
424 ms |
16560 KB |
Output is correct |
7 |
Correct |
412 ms |
16560 KB |
Output is correct |
8 |
Correct |
398 ms |
16560 KB |
Output is correct |
9 |
Correct |
466 ms |
16560 KB |
Output is correct |
10 |
Correct |
436 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
357 ms |
16728 KB |
Output is correct |
2 |
Incorrect |
43 ms |
16728 KB |
Error - advice is too long |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
16728 KB |
Error - advice is too long |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
441 ms |
16728 KB |
Output is partially correct - 1700000 bits used |
2 |
Partially correct |
440 ms |
16728 KB |
Output is partially correct - 1700000 bits used |
3 |
Partially correct |
390 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
4 |
Partially correct |
388 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
5 |
Partially correct |
401 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
6 |
Partially correct |
443 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
7 |
Partially correct |
451 ms |
16744 KB |
Output is partially correct - 1697263 bits used |
8 |
Partially correct |
402 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
9 |
Partially correct |
495 ms |
16744 KB |
Output is partially correct - 1700000 bits used |
10 |
Partially correct |
526 ms |
16744 KB |
Output is partially correct - 1700000 bits used |