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 <512> code;
if(n == 1)
{
send(m[0]);
return;
}
for(int i = 0; i < 8 * n; i ++)
code[i] = 0;
int j;
for(int i = 0; i < n; i ++)
{
j = 0;
int copie = m[i];
while(copie)
{
code[8 * (i + 1) - 1 - j] = copie % 2;
copie >>= 1;
j ++;
}
}
int cnt1 = 0, cnt0 = 0, flag = 0;
for(int i = 0; i < 4 * n; i ++)
{
if(code[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(code[i] == 1)
cnt1 ++;
else
cnt0 ++;
}
flag = 0;
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[])
{
if(l == 1)
{
output(x[0]);
return;
}
bitset <512> code;
sort(x, x + l);
int cnt, flag1 = 0, flag2 = 0, i;
cnt = 1, i = 0;
if(x[i] == 0)
{
while(i < l - 1 && x[i] == x[i + 1])
{
i ++;
cnt ++;
}
if(cnt >= 4)
flag2 = 1;
i ++;
}
cnt = 1;
if(x[i] == 1)
{
while(i < l - 1 && x[i] == x[i + 1])
{
i ++;
cnt ++;
}
if(cnt >= 4)
flag1 = 1;
i ++;
}
for(int i = 0; i < 4 * n; i ++)
code[i] = 1 - flag1;
for(int i = 4 * n; i < 8 * n; i ++)
code[i] = 1 - flag2;
i = 0;
for(int i = 0; i < l; i ++)
{
cnt = 1;
while(i < l - 1 && 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[4 * n + x[i]] = flag2;
}
for(int i = 7; i < 8 * n; i +=8)
{
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... |