# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386937 | godwind | Parrots (IOI11_parrots) | C++17 | 0 ms | 0 KiB |
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 <vector>
using namespace std;
void encode(int n, int M[])
{
vector<int> is(n);
for (int i = 0; i < n; ++i) {
int FIRST = M[i] / 16;
int SECOND = M[i] % 16;
if (FIRST * 16 + i > 255) {
exit(-1);
}
if (SECOND * 16 + i > 255) {
exit(-1);
}
send(FIRST * 16 + i);
send(SECOND * 16 + i);
if (FIRST < SECOND) {
is[i] = false;
} else {
is[i] = true;
}
}
int mask = 0;
for (int i = 0; i < n; ++i) {
if (is[i]) {
mask += (1 << i);
}
}
for (int it = 0; it < 10; ++it) {
send(mask);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
void decode(int n, int L, int X[])
{
vector<int> ans(n), is(n);
vector< vector<int> > parts(n);
map<int, int> cnt;
for (int i = 0; i < L; ++i) {
++cnt[X[i]];
}
auto proceed = [&] (int mask) {
int FP = mask / 16;
int SP = mask % 16;
int id = SP;
parts[id].push_back(FP);
};
for (auto P : cnt) {
int mask = P.first;
int cn = P.second;
if (cn == 10) {
for (int i = 0; i < n; ++i) {
is[i] = (mask >> i) & 1;
}
} else {
int least = 0;
if (cn > 10) {
least = cn - 10;
} else {
least = cn;
}
for (int it = 0; it < least; ++it) {
proceed(mask);
}
}
}
for (int i = 0; i < n; ++i) {
if (parts[i].size() != 2) {
exit(-1);
}
sort(parts[i].begin(), parts[i].end());
if (!is[i]) {
ans[i] = parts[i][1] * 16 + parts[i][0];
} else {
ans[i] = parts[i][0] * 16 + parts[i][1];
}
}
for (int i = 0; i < n; ++i) {
output(ans[i]);
}
}