#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void encode(int N, int M[])
{
vector<int> Tab;
for (int i = 0; i < N; i++)
{
for (int j = 0; j < 8; j++)
{
Tab.push_back((M[i] & (1 << j)) ? 1 : 0);
}
}
srand(31985654);
int ones = 0;
for (int i = 0; i < Tab.size(); i++)
{
int x = rand() % 2;
if (x)
Tab[i] = 1 - Tab[i];
if (Tab[i])
ones++;
}
int swapped = 0;
if (ones > 255)
swapped = 1;
int buff = 0;
if (swapped)
buff++;
else
send(buff);
for (int i = 0; i < Tab.size(); i++)
{
if (swapped)
Tab[i] = 1 - Tab[i];
if (Tab[i])
buff++;
else
send(buff);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int N, int L, int X[])
{
vector<int> Tab;
for (int i = 0; i < L; i++)
Tab.push_back(X[i]);
sort(Tab.begin(), Tab.end());
vector<int> message;
int buff = 0;
for (int i = 0; i < 256; i++)
{
while (buff < Tab.size() && Tab[buff] == i)
{
message.push_back(0);
buff++;
}
message.push_back(1);
}
if (message[0])
{
for (int i = 1; i < message.size(); i++)
message[i] = 1 - message[i];
}
srand(31985654);
for (int i = 1; i < message.size(); i++)
{
int x = rand() % 2;
if (x)
message[i] = 1 - message[i];
}
buff = 1;
for (int i = 0; i < N; i++)
{
int x = 0;
for (int j = 0; j < 8; j++)
{
x *= 2;
if (message[buff])
x++;
buff++;
}
output(x);
}
}
# | 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... |