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;
static const vector<int> b[4] = {{2, 3, 3}, {1, 2, 3, 2}, {1, 1, 2, 2, 2}, {2, 2, 1, 1, 1, 1}};
static bool check(int u, vector<int> v) {
bool ret = true;
for (int i = 0, bsz = 0, prv = 0; i < v.size() && ret; i++) {
bsz += v[i];
int x = u >> 8 - bsz;
x -= x >> v[i] << v[i];
ret &= (v[i] == 1 ? 6|x : v[i] == 2 ? 4|x : x) >= prv;
prv = x >= prv ? x : (4|x) >= prv ? 4|x : 6|x;
}
return ret;
}
void encode(int N, int *M) {
for (int i = 0; i < N; i++) {
vector<int> v;
for (int j = 0; j < 4; j++) {
if (check(M[i], b[j])) {
v = b[j];
break;
}
}
for (int j = 0, bsz = 0, prv = 0; j < v.size(); j++) {
bsz += v[j];
int x = M[i] >> 8 - bsz;
x -= x >> v[j] << v[j];
prv = x >= prv ? x : (4|x) >= prv ? 4|x : 6|x;
send(i << 3 | prv);
}
}
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;
static const vector<int> b[4] = {{2, 3, 3}, {1, 2, 3, 2}, {1, 1, 2, 2, 2}, {2, 2, 1, 1, 1, 1}};
void decode(int N, int L, int *X) {
sort(X, X+L);
for (int l = 0, r = 0; l < L && r < L; ) {
for (; r < L && (X[r] >> 3) == (X[l] >> 3); r++);
int v = 0;
for (int i = l; i < r; i++) {
v = v << b[r-l-3][i-l] | X[i] - (X[i] >> b[r-l-3][i-l] << b[r-l-3][i-l]);
}
output(v);
l = r;
}
}
Compilation message (stderr)
encoder.cpp: In function 'bool check(int, std::vector<int>)':
encoder.cpp:9:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for (int i = 0, bsz = 0, prv = 0; i < v.size() && ret; i++) {
| ~~^~~~~~~~~~
encoder.cpp:11:18: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
11 | int x = u >> 8 - bsz;
| ~~^~~~~
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:28:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int j = 0, bsz = 0, prv = 0; j < v.size(); j++) {
| ~~^~~~~~~~~~
encoder.cpp:30:22: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
30 | int x = M[i] >> 8 - bsz;
| ~~^~~~~
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:14:34: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
14 | v = v << b[r-l-3][i-l] | X[i] - (X[i] >> b[r-l-3][i-l] << b[r-l-3][i-l]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |