#include "registers.h"
#include <bits/stdc++.h>
using namespace std;
const int maxb = 2000;
const int maxn = 100;
const int logn = 7;
class Registers{
private:
vector<int> free;
int cont = 0;
int create(){ return ++cont; }
public:
int get(){
if( free.empty() ) return create();
int x = free.back(); free.pop_back();
return x;
}
void take_back( int id ){
free.push_back(id);
}
} reg;
void append_extract_even( int goal, int source, int k, int delta ){
vector<bool> v(maxb);
for( int i = 0; i < maxb; i += 2*delta ){
for( int j = i; j < i + k; j++ ) v[j] = true;
}
int aux = reg.get();
append_store( aux, v );
append_and( goal, source, aux );
reg.take_back(aux);
}
void append_extract_odd( int goal, int source, int k, int delta ){
append_right( goal, source, delta );
append_extract_even( goal, goal, k, delta );
}
void append_subtract( int goal, int a, int b ){
append_not( goal, b );
append_add( goal, goal, a );
}
void append_spread( int goal, int k ){
int aux = reg.get();
append_right( aux, goal, k );
append_and( goal, aux, goal );
append_or( goal, aux, goal );
reg.take_back(aux);
}
void append_complete( int goal, int qtd, int k, int delta ){
vector<bool> v(maxb);
for( int i = 0; i < maxb; i += 2*delta ) if( i/(2*delta) >= qtd ){
for( int j = i; j < i + k; j++ ) v[j] = true;
}
int aux = reg.get();
append_store( aux, v );
append_or( goal, goal, aux );
reg.take_back(aux);
}
void get_min( int n, int k ){
int a = reg.get();
int b = reg.get();
int total = n;
for( int i = 1; total > 1; i *= 2 ){
append_extract_even( a, 0, k, k*i );
append_extract_odd( b, 0, k, k*i );
int qtda = (total + 1)/2;
int qtdb = total/2;
append_complete( a, qtda, k, k*i );
append_complete( b, qtdb, k, k*i );
int sub = reg.get();
append_subtract( sub, a, b );
append_spread( sub, k );
append_and( 0, sub, a );
append_not( sub, sub );
append_and( sub, sub, b );
append_or( 0, 0, sub );
total = qtda;
}
}
void sort( int n, int k ){}
void construct_instructions( int s, int n, int k, int q ){
if( s == 0 ) get_min( n, k );
else sort( n, k );
}
# | 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... |