# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221454 | emil_physmath | 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 "parrots.h"
#include <iostream>
#include <set>
#include <map>
using namespace std;
const int n_bits = 5;
multiset<int> code1[256];
map<multiset<int>, int> coderev1;
void Init1()
{
static int cnt = 0;
static set<multiset<int> > usedcodes;
int a[5];
#define specfor(i) for (a[(i)] = 0; a[(i)] < (1 << (8 - n_bits)) && cnt < 256; ++a[(i)])
specfor(0)
specfor(1)
specfor(2)
specfor(3)
specfor(4)
{
multiset<int> curcode(a, a + 5);
if (usedcodes.find(curcode) != usedcodes.end()) continue;
coderev1[curcode] = cnt;
code1[cnt++] = curcode;
usedcodes.insert(curcode);
}
}
multiset<int> code2[256];
map<multiset<int>, int> coderev2;
void Init2()
{
static int cnt = 0;
static set<multiset<int> > usedcodes;
if (cnt == 256)
return;
coderev2[multiset<int>()] = 0;
code2[0] = multiset<int>();
cnt = 1;
int a[15];
for (int j = 1; j <= 7 && cnt < 256; ++j)
#define specfor(i) for (a[(i)] = 0; a[(i)] < (1 << (8 - (n_bits + 1))) && cnt < 256; ++a[(i)])
specfor(0)
specfor(1)
specfor(2)
specfor(3)
specfor(4)
specfor(5)
specfor(6)
{
{
multiset<int> curcode(a, a + j);
if (usedcodes.find(curcode) != usedcodes.end()) continue;
coderev2[curcode] = cnt;
code2[cnt++] = curcode;
usedcodes.insert(curcode);
cerr << cnt << '\t';
}
}
}
void encode(int n, int a[]) {
if (n <= 32)
Init1();
else
Init2();
auto& code = (n <= 32 ? code1 : code2);
int nbits = n_bits;
if (n > 32)
++nbits;
for (int i = 0; i < n; ++i)
for (int y: code[a[i]])
send(i | (y << nbits));
}
multiset<int> got[256];
void decode(int n, int l, int x[])
{
int nbits = n_bits;
if (n <= 32)
Init1();
else
{
++nbits;
Init2();
}
auto& coderev = (n <= 32 ? coderev1 : coderev2);
for (int i = 0; i < l; ++i)
got[x[i] & ((1U << nbits) - 1)].insert(x[i] >> nbits);
for (int i = 0; i < n; ++i)
{
cerr << coderev[got[i]] << ' ';
output(coderev[got[i]]);
}
for (int i = 0; i < 256; ++i)
got[i].clear();
}