#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void encode(int N, int M[])
{
int forward_cnt = 0, backward_cnt = 0;
vector<int> forward, backward;
for (int i = 0; i < N; i++) {
int msg = 0;
msg += (i << 2);
int tmp = M[i];
for (int j = 3; j >= 0; j--) {
int cnt = tmp % 4;
for (int k = 1; k <= cnt; k++) {
forward.push_back(msg + j);
forward_cnt++;
}
cnt ^= 3;
for (int k = 1; k <= cnt; k++) {
backward.push_back(msg + j);
backward_cnt++;
}
tmp >>= 2;
}
}
if (backward_cnt < forward_cnt) {
for (int i = 0; i < backward_cnt; i++) send(backward[i]);
for (int i = 0; i < 4; i++) send(255);
}
else {
for (int i = 0; i < forward_cnt; i++) send(forward[i]);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int N, int L, int X[])
{
int origin[64];
int back_cnt = 0;
for (int i = 0; i < L; i++) {
if (X[i] == 255) back_cnt++;
}
if (back_cnt >= 4) {
for (int i = 0; i < N; i++) origin[i] = 255;
int cnt = 0;
for (int i = 0; i < L; i++) {
if (cnt == 4) break;
if (X[i] == 255) {
X[i] = -1;
cnt++;
}
}
for (int i = 0; i < L; i++) {
if (X[i] == -1) continue;
int idx = X[i] >> 2;
int idx_inner = X[i] % 4;
origin[idx] -= 1 << ((3 - idx_inner) * 2);
}
}
else {
for (int i = 0; i < N; i++) origin[i] = 0;
for (int i = 0; i < L; i++) {
int idx = X[i] >> 2;
int idx_inner = X[i] % 4;
origin[idx] += 1 << ((3 - idx_inner) * 2);
}
}
for (int i = 0; i < N; i++) {
output(origin[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1632 KB |
Output is correct |
2 |
Correct |
6 ms |
1968 KB |
Output is correct |
3 |
Correct |
7 ms |
2184 KB |
Output is correct |
4 |
Correct |
7 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2184 KB |
Output is correct |
2 |
Correct |
7 ms |
2184 KB |
Output is correct |
3 |
Correct |
7 ms |
2184 KB |
Output is correct |
4 |
Correct |
9 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2184 KB |
Output is correct |
2 |
Correct |
7 ms |
2184 KB |
Output is correct |
3 |
Correct |
7 ms |
2184 KB |
Output is correct |
4 |
Correct |
11 ms |
2184 KB |
Output is correct |
5 |
Correct |
10 ms |
2184 KB |
Output is correct |
6 |
Correct |
10 ms |
2184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
6 ms |
2184 KB |
Output is partially correct - P = 6.187500 |
2 |
Partially correct |
9 ms |
2184 KB |
Output is partially correct - P = 6.093750 |
3 |
Partially correct |
11 ms |
2184 KB |
Output is partially correct - P = 6.090909 |
4 |
Partially correct |
12 ms |
2432 KB |
Output is partially correct - P = 6.020000 |
5 |
Partially correct |
12 ms |
2432 KB |
Output is partially correct - P = 6.033333 |
6 |
Partially correct |
13 ms |
2432 KB |
Output is partially correct - P = 6.047619 |
7 |
Partially correct |
13 ms |
2440 KB |
Output is partially correct - P = 6.031250 |