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 <bits/stdc++.h>
using namespace std;
vector<int> factorize(int n) {
vector<int> factors;
for (int i=2; i<=n; i++) {
if (i * i > n) {
factors.push_back(n);
break;
}
if (n % i == 0) {
factors.push_back(i);
n /= i;
i--;
}
}
return factors;
}
void encode(int N, int M[])
{
vector<vector<int>> vals(N);
for (int i=0; i<N; i++) {
int delta = 0;
bool done = false;
vector<int> facs;
while (!done) {
if (M[i] - delta == 0) break;
if (M[i] - delta == 1) {
delta++;
} else facs = factorize(M[i] - delta);
bool can = true;
for (int f : facs) {
if (f > 9) can = false;
}
if ((int)facs.size() > 10 - (delta+7)/8) can = false;
if (can) {
done = true;
while (delta != 0) {
int val = i;
val = val << 4; // id de somar é 0
val += min(8, delta)-1; // -1 porque o 0 não é opção
delta -= min(8, delta);
vals[i].push_back(val);
}
// manda fatores
for (int f : facs) {
int val = i;
val = val << 1;
val++; // id de fator é 1
val = val << 3;
val += f-2; // 0 nem 1 é fator válido, 9 é; 9-2=7 => (base 2)111
vals[i].push_back(val);
}
} else {
delta++;
// if (M[i] < 0) cout << "error " << M[i]+delta << endl;
}
}
}
for(int i=0; i<N; i++) {
for (int j=0; j<(int)vals[i].size(); j++) {
send(vals[i][j]);
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) {
return a > b;
}
void decode(int N, int L, int X[])
{
sort(X, X+L, cmp); // soma > por último
int last = 0; int act = 0;
vector<int> vals(N, -1);
for(int i=0; i<L; i++) {
int id = (X[i] >> 4);
int op = ((X[i] >> 3) & 1);
int val = ((X[i]) & 7); // 00000111
if (op == 0) val++;
else val += 2;
// cout << id << ' ' << op << ' ' << val << endl;
if (vals[id] == -1) {
if (op == 0) vals[id] = 0;
else vals[id] = 1;
}
if (op == 0) {
vals[id] += val;
// cout << "+" << val << endl;
} else vals[id] *= val;
}
for (int v : vals) {
// cout << v << endl;
if (v == -1) output(0);
else output(v);
}
}
Compilation message (stderr)
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:13:7: warning: unused variable 'last' [-Wunused-variable]
13 | int last = 0; int act = 0;
| ^~~~
decoder.cpp:13:21: warning: unused variable 'act' [-Wunused-variable]
13 | int last = 0; int act = 0;
| ^~~
# | 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... |