# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98199 | SpeedOfMagic | 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 "grader.h"
#include <bits/stdc++.h>
using namespace std;
map<int, int> hsh;
vector<int> invHsh;
bool inverse[6] = {0, 0, 0, 0, 0, 0};
void encode(int N, int M[]) {
int p = 0;
for (int i = 0; i < N; i++)
hsh[M[i]] = 0;
for (auto i : hsh) {
invHsh.push_back(i.first);
hsh[i.first] = p++;
}
for (int i = 0; i < N; i++)
M[i] = hsh[M[i]];
//for (int i =0 ; i < N; i++) cout << M[i] << " "; cout << endl;
int cnt[6] = {0, 0, 0, 0, 0, 0};
for (int i = 0; i < N; i++)
for (int j = 0; j < 6; j++)
if (M[i] & (1 << j))
cnt[j]++;
for (int i = 0; i < 6; i++)
if (cnt[i] > N / 2)
inverse[i] = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 6; j++) {
if (inverse[j])
M[i] ^= (1 << j);
if (M[i] & (1 << j)) {
send((i << 2) + (j % 4)); //location, then number of bit = 1
if (j > 3)
send((i << 2) + (j % 4));
}
}
}
}
void decode(int N, int L, int X[]) {
int res[N];
int cnt[N][4];
memset(cnt, 0, sizeof cnt);
memset(res, 0, sizeof res);
for (int i = 0; i < L; i++) {
int ind = X[i] >> 2;
int num = X[i] % 4;
cnt[ind][num]++;
}
for (int i = 0; i < N; i++)
for (int j = 0; j < 4; j++) {
assert(cnt[i][j] <= 3);
if (cnt[i][j] % 2)
res[i] += (1 << j);
if (cnt[i][j] > 1)
res[i] += (1 << (j + 4));
}
for (int i : res) {
for (int j = 0; j < 6; j++)
if (inverse[j])
i ^= (1 << j);
//cout << i << " " << invHsh[i]; cout << endl;
output(invHsh[i]);
}
}