#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void dbg(int n) {
for (int i = 0; i < 8; ++i) {
cout << (n >> i & 1);
}
cout << endl;
}
void encode(int N, int M[])
{
int index = 0;
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < N; ++i) {
// dbg(M[i]);
for (int j = 0; j < 8; j += 2) {
int now = index++;
int state = 0;
for (int k = j; k < j + 2; ++k) {
state += (1 << (k - j)) * (M[i] >> k & 1);
}
cnt1 += state;
cnt2 += 3 - state;
// cout << state << "\n";
for (int k = 0; k < state; ++k) {
// send(now);
// dbg(now);
}
}
}
if (cnt1 <= cnt2) {
index = 0;
for (int i = 0; i < N; ++i) {
// dbg(M[i]);
for (int j = 0; j < 8; j += 2) {
int now = index++;
int state = 0;
for (int k = j; k < j + 2; ++k) {
state += (1 << (k - j)) * (M[i] >> k & 1);
}
// cnt1 += state;
// cnt2 += 3 - state;
// cout << state << "\n";
for (int k = 0; k < state; ++k) {
send(now);
// dbg(now);
}
}
}
} else {
index = 0;
for (int i = 0; i < N; ++i) {
// dbg(M[i]);
for (int j = 0; j < 8; j += 2) {
int now = index++;
int state = 0;
for (int k = j; k < j + 2; ++k) {
state += (1 << (k - j)) * (M[i] >> k & 1);
}
// cnt1 += state;
// cnt2 += 3 - state;
// cout << state << "\n";
for (int k = 0; k < 3 - state; ++k) {
send(now);
// dbg(now);
}
}
}
for (int i = 0; i < 4; ++i) {
send(255);
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int N, int L, int X[])
{
// cerr << "HERE!\n";
vector<int> res(N);
map<int, int> mp;
{
int index = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 8; j += 2) {
mp[index] = 0;
index += 1;
}
}
}
for (int i = 0; i < L; ++i) {
mp[X[i]] += 1;
}
// for (auto& [x, c] : mp) {
// cerr << x << " " << c << "\n";
// }
// cerr << "\n";
int rev = 0;
if (mp[255] >= 4) {
mp[255] -= 4;
rev = 1;
}
// for ()
int bit = 1, index = 0;
for (auto& [x, cnt] : mp) {
// cerr << index << " " << N << "\n";
if (index >= N) continue;
res[index] += bit * (rev == 1 ? 3 - cnt : cnt);
bit <<= 2;
// cout << index << " " << bit << " " << cnt << "\n";
if (bit == 256) {
index += 1;
bit = 1;
}
}
for (int i = 0; i < N; ++i) {
output(res[i]);
}
}
# | 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... |