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 "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void encode( int N, int M[] ){
/* IDEA 5 :
Generate 'matrix' where rows are the numbers themselves.
Foreach 1 in the matrix : ( xi%32, yi )
0 <= xi < 32 0 <= yi < 8
represent pair( xi, yi ) as [ xxxxx yyy ]
if x >= 32 then send the pair twice
*/
// cout << endl << "ENCODER" << endl;
int mtx[N] = {};
for(int i=0;i<N;i++){
for(int j=0;j<8;j++) mtx[i] |= M[i] & ( 1 << j );
}
vector <int> pairs;
// for(int i=0;i<N;i++) cout << bitset<8>(mtx[i]) << endl;
// cout << endl;
int N1 = min( N, 32 );
for(int i=0;i<N1;i++) for(int j=0;j<8;j++) if( mtx[i] & ( 1 << j ) ) pairs.push_back( ( i << 3 ) | j );
for(int i=32;i<N;i++) for(int j=0;j<8;j++) if( mtx[i] & ( 1 << j ) ) { pairs.push_back( ( (i%32) << 3 ) | j ); pairs.push_back( ( (i%32) << 3 ) | j ); }
// for(int i=0;i<pairs.size();i++) cout << bitset<8>(pairs[i]) << endl;
for(int i=0;i<pairs.size();i++) send( pairs[i] );
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode( int N, int L, int X[] ){
/* IDEA 5 :
Generate 'matrix' where rows are the numbers themselves.
Foreach 1 in the matrix : ( xi%32, yi )
0 <= xi < 32 0 <= yi < 8
represent pair( xi, yi ) as [ xxxxx yyy ]
if x >= 32 then send the pair twice
*/
// cout << endl << "DECODER" << endl;
int freq[256] = {};
for(int i=0;i<L;i++) freq[X[i]]++;
int mtx[N] = {};
for(int i=0;i<L;i++){
int xi = 0, yi = 0;
for(int j=7;j>=3;j--) xi |= X[i] & ( 1 << j );
xi >>= 3;
for(int j=2;j>=0;j--) yi |= X[i] & ( 1 << j );
if( freq[X[i]] == 1 ) mtx[xi] |= 1 << yi;
else if( freq[X[i]] == 2 ) mtx[xi+32] |= 1 << yi;
else if( freq[X[i]] == 3 ){
mtx[xi] |= 1 << yi;
mtx[xi+32] |= 1 << yi;
}else cout << "brat" << endl;
// cout << xi << ' ' << yi << endl;
}
// for(int i=0;i<N;i++) cout << bitset<8>(mtx[i]) << endl;
for(int i=0;i<N;i++) output(mtx[i]);
}
Compilation message (stderr)
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<pairs.size();i++) send( pairs[i] );
~^~~~~~~~~~~~~
# | 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... |