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 <iostream>
#include <vector>
using namespace std;
void encode(int N, int M[])
{
vector <int> v1, v2 = {255, 255, 255, 255};
for (int i = 0; i < N; i++)
for (int j = 0; j < 4; j++)
{
bool bit1 = M[i] & (1 << (2 * j));
bool bit2 = M[i] & (1 << (2 * j + 1));
int val = bit1 + 2 * bit2;
int pos = 4 * i + j;
for (int k = 0; k < val; k++)
v1.push_back(pos);
for (int k = 0; k < 3 - val; k++)
v2.push_back(pos);
}
if (v1.size() < v2.size())
for (auto it : v1)
send(it);
else
for (auto it : v2)
send(it);
}
#include "decoder.h"
#include "decoderlib.h"
#include <iostream>
#include <vector>
using namespace std;
void decode(int N, int L, int X[])
{
vector <int> freq(260, 0);
for (int i = 0; i < L; i++)
freq[X[i]]++;
int ok;
if (freq[255] < 4)
ok = 0;
else
{
ok = 1;
freq[255] = freq[255] - 4;
}
for (int i = 0; i < N; i++)
{
int val = 0;
for (int j = 0; j < 4; j++)
{
int aux = freq[4 * i + j];
if (aux == 1)
val = val | (1 << (2 * j));
else
if (aux == 2)
val = val | (1 << (2 * j + 1));
else
if (aux == 3)
{
val = val | (1 << (2 * j));
val = val | (1 << (2 * j + 1));
}
}
if (ok == 1)
val = (~val) & 255;
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... |