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 print(int x){
for(int i=128;i>=0;i>>=1){
cout << ((x>>i)&1);
}cout << '\n';
}
int A[100];
void encode(int n, int aa[]){
for(int i=0;i<n;i++)A[i] = aa[i];
int best_xor = 0;
for(int j=0;j<8;j++){
int cnt = 0;
for(int i=0;i<n;i++){
cnt += (A[i]>>j&1);
}if(cnt > n/2)best_xor |= (1<<j);
}
send(best_xor);
send(best_xor);
send(best_xor);
send(best_xor);
for(int i=0;i<n;i++)A[i] ^= best_xor;
for(int i=0;i<n;i++){
while(A[i] >= 64){
A[i] -= 64;
send(i | (3<<6));
}
while(A[i] >= 16){
A[i] -= 16;
send(i | (2<<6));
}
while(A[i] >= 4){
A[i] -= 4;
send(i | (1<<6));
}
while(A[i] >= 1){
A[i] -= 1;
send(i | (0<<6));
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
int a[256], cnt[256];
void decode(int n, int len, int x[]){
for(int i=0;i<256;i++)a[i]=0,cnt[i]=0;
for(int i=0;i<len;i++)cnt[x[i]]++;
int best_xor=0;
for(int i=0;i<256;i++){
if(cnt[i] > 3){
cnt[i] -= 4;
best_xor = i;
break;
}
}
for(int i=0;i<len;i++){
if(!cnt[x[i]])continue;
int type = (x[i] & 192)>>6;
int ind = x[i] & 63;
if(type == 3)a[ind] += 64,cnt[x[i]]--;
if(!cnt[x[i]])continue;
if(type == 2)a[ind] += 16,cnt[x[i]]--;
if(!cnt[x[i]])continue;
if(type == 1)a[ind] += 4,cnt[x[i]]--;
if(!cnt[x[i]])continue;
if(type == 0)a[ind] += 1,cnt[x[i]]--;
if(!cnt[x[i]])continue;
}
//~ for(int i=0;i<n;i++)cout << a[i] << ' ';cout << '\n';
for(int i=0;i<n;i++)output(a[i]^best_xor);
}
# | 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... |