# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052041 | Piokemon | 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 <bits/stdc++.h>
typedef __int128 ll;
void encode(int n, int m[]){
ll ilosc[41][33];
// poz ter
for (int x=0;x<40;x++){
for (int y=0;y<32;y++)ilosc[x][y]=0;
}
ilosc[0][0]=1;
for (int x=0;x<40;x++){
for (int y=0;y<32;y++){
ilosc[x][y+1]+=ilosc[x][y];
ilosc[x+1][y]+=ilosc[x][y];
}
}
vector<int> dupa;
for (int blok=0;blok*8<=n;blok++){
ll wart=0;
for (int x=0;x<8;x++){
if (blok*8+x>=n)wart=wart*(ll)256;
else wart=wart*(ll)256+(ll)m[blok*8+x];
}
int nr=0; //rang od blok*32 do (blok+1)*32-1;
for (int x=0;x<40;x++){
while (nr<32 && ilosc[40-x][32-nr]>=wart){
wart-=ilosc[40-x][32-nr];
nr++;
}
dupa.push_back(nr+blok*32);
}
}
for (int x:dupa)send(x);
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
typedef __int128 ll;
void decode(int n, int l, int x[])
{
ll ilosc[41][33];
// poz ter
for (int z=0;z<40;z++){
for (int y=0;y<32;y++)ilosc[z][y]=0;
}
ilosc[0][0]=1;
for (int z=0;z<40;z++){
for (int y=0;y<32;y++){
ilosc[z][y+1]+=ilosc[z][y];
ilosc[z+1][y]+=ilosc[z][y];
}
}
sort(x,x+l);
vector<int> dupa2;
for (int blok=0;blok*8<n+7;blok++){
// bieremy papugi od blok*40 do blok*40+39
ll wart=0;
int nr=0;
for (int y=0;y<40;y++){
x[blok*40+y]-=blok*32;
while(x[blok*40+y]>nr){
wart+=ilosc[40-y][32-nr];
nr++;
}
}
vector<int> temp;
for (int y=0;y<8;y++){
temp.push_back(wart%(ll)256);
wart/=(ll)256;
}
for (int y=7;y>=0;y--)dupa.push_back(temp[y]);
}
for (int y:dupa) output(y);
}