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 <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;
/// ratio 6N + 8(flaguri)
void encode(int n, int m[])
{
bitset <256> code;
for(int i = 0; i < 8 * n; i ++)
code[i] = 0;
int j = 7;
for(int i = 0; i < n; i ++, j += 8)
{
while(m[i])
{
code[j] = m[i] % 2;
m[i] >>= 1;
}
}
int cnt1 = 0, cnt0 = 0, flag = 0;
for(int i = 0; i < 4 * n; i ++)
{
if(m[i] == 1)
cnt1 ++;
else
cnt0 ++;
}
if(cnt1 <= cnt0)
{
flag = 1;
send(1);
send(1);
send(1);
send(1);
}
for(int i = 0; i < 4 * n; i ++)
{
if(code[i] == flag)
send(i);
}
///////////////////////////////////
cnt1 = 0, cnt0 = 0;
for(int i = 4 * n; i < 8 * n; i ++)
{
if(m[i] == 1)
cnt1 ++;
else
cnt0 ++;
}
if(cnt1 <= cnt0)
{
flag = 1;
send(0);
send(0);
send(0);
send(0);
}
for(int i = 4 * n; i < 8 * n; i ++)
{
if(code[i] == flag)
{
send(i - 4 * n);
send(i - 4 * n);
}
}
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;
void decode(int n, int l, int x[])
{
bitset <256> code;
for(int i = 0; i < 8 * n; i ++)
code[i] = 0;
sort(x, x + l);
int cnt, flag1 = 0, flag2 = 0, i;
cnt = 1, i = 0;
if(x[i] == 0)
{
while(i < l && x[i] == x[i + 1])
{
i ++;
cnt ++;
}
if(cnt >= 4)
flag2 = 1;
i ++;
}
if(x[i] == 1)
{
while(i < l && x[i] == x[i + 1])
{
i ++;
cnt ++;
}
if(cnt >= 4)
flag1 = 1;
i ++;
}
for(int i = 0; i < 4 * n; i ++)
code[i] = flag1;
for(int i = 4 * n; i < 8 * n; i ++)
code[i] = flag2;
i = 0;
for(int i = 0; i < l; i ++)
{
cnt = 1;
while(i < l && x[i] == x[i + 1])
{
i ++;
cnt ++;
}
if((x[i] == 0 || x[i] == 1) && cnt >= 4)
cnt -=4;
if(cnt == 1 || cnt == 3)
code[x[i]] = flag1;
if(cnt == 2 || cnt == 3)
code[x[i]] = flag2;
}
for(int i = 7; i < 8 * n; i ++)
{
int pow = 1, nr = 0;
for(int j = 0; j <= 7; j ++, pow <<= 1)
nr += code[i - j] * pow;
output(nr);
}
}
# | 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... |