이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
void sendcnt(int a,int x){
for(int i=0;i<x;i++){
send(a);
}
}
void encode(int N, int M[])
{
if(N<=32){
//binary system
for(int num=0;num<N;num++){
int pos=0;
while(M[num]>0){
if(M[num]&1){
send((num<<3)|pos);
}
M[num]>>=1;
pos++;
}
}
}else{
//4-ary system
int cnt1=0,cnt2=0;
for(int num=0;num<N;num++){
int pos=0;
while(M[num]>0){
int cnt=M[num]&3;//mod4=mod(2^2), we keep last 2 digits
cnt1+=cnt;
cnt2+=(3-cnt);
M[num]>>=2;
pos++;
}
}
bool change=(cnt2<cnt1);
if(change) sendcnt(255,4);
for(int num=0;num<N;num++){
int pos=0;
while(M[num]>0){
int cnt=M[num]&3;//mod4=mod(2^2), we keep last 2 digits
sendcnt((num<<2)|pos,change?3-cnt:cnt);
M[num]>>=2;
pos++;
}
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int N, int L, int X[])
{
map<int,int> freq;
for(int i=0;i<L;i++){
freq[X[i]]++;
}
if(N<=32){
//binary system
for(int num=0;num<N;num++){
int val=0;
for(int pos=0;pos<8;pos++){
int mask=(num<<3)|pos;
if(freq.count(mask)){
val|=(1<<pos);
}
}
output(val);
}
}else{
//4-ary system
bool change=false;
if(freq.count(255)){
if(freq[255]>=4){
change=true;
freq[255]-=4;
}
}
for(int num=0;num<N;num++){
int val=0;
for(int pos=0;pos<4;pos++){
int mask=(num<<2)|pos;
if(freq.count(mask)){
val|=(1<<(2*pos))*(change?3-freq[mask]:freq[mask]);
}
}
output(val);
}
}
}
# | 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... |