# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94658 | andy627 | 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 <stdio.h>
#include <vector>
#include <algorithm>
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
int n1;
int M1[64];
void en_solve123(){
for(int i=0;i<n1;i++){
for(int j=0;j<8;j++){
send((i<<4)+(j<<1)+!!(M1[i]&(1<<j)));
}
}
}
vector<pii> vc(4);
void en_solve45(){
for(int i=0;i<4;i++) vc[i].ss=i;
for(int i=0;i<n1;i++){
for(int j=0;j<4;j++) vc[!!(M1[i]&(1<<(j<<1)))+(!!(M1[i]&(1<<(j<<1|1)))<<1)].ff++;
}
sort(vc.begin(),vc.end());
reverse(vc.begin(),vc.end());
int cha[4];
for(int i=0;i<4;i++) cha[vc[i].ss]=i;
for(int i=0;i<4;i++) send((cha[0]<<6)+(cha[1]<<4)+(cha[2]<<2)+cha[3]);
for(int i=0;i<n1;i++){
for(int j=0;j<4;j++){
//printf("%d %d %d\n",i,j,!!(M1[i]&(1<<(j<<1)))+(!!(M1[i]&(1<<(j<<1|1)))<<1));
for(int k=0;k<cha[!!(M1[i]&(1<<(j<<1)))+(!!(M1[i]&(1<<(j<<1|1)))<<1)];k++) send((i<<2)+j);
}
}
}
void encode(int N, int _M[]){
n1=N;
for(int i=0;i<n1;i++) M1[i]=_M[i];
//printf("en\n"); for(int i=0;i<n1;i++) printf("%d ",M1[i]); printf("\n");
en_solve45(); return;
if(n1<=16) en_solve123();
else en_solve45();
}
#include "decoder.h"
#include <stdio.h>
#include <algorithm>
using namespace std;
int n2,l;
int X[1111],M2[64];
void de_solve123(){
for(int i=0;i<l;i++) M2[X[i]>>4]+=(X[i]%2)*(1<<((X[i]%16)>>1));
for(int i=0;i<n2;i++) output(M2[i]);
//printf("de\n"); for(int i=0;i<n2;i++) printf("%d ",M2[i]); printf("\n");
}
int cnt[64][4];
void de_solve45(){
for(int i=0;i<n2;i++){
for(int j=0;j<4;j++) cnt[i][j]=0;
}
//for(int i=0;i<n2;i++) printf("%d %d %d %d\n",cnt[i][0],cnt[i][1],cnt[i][2],cnt[i][3]); printf("\n");
for(int i=0;i<l;i++) cnt[X[i]>>2][X[i]%4]++;
//for(int i=0;i<l;i++) printf("%d %d\n",X[i]>>2,X[i]%4);
//for(int i=0;i<n2;i++) printf("%d %d %d %d\n",cnt[i][0],cnt[i][1],cnt[i][2],cnt[i][3]); printf("\n");
int rev[4];
for(int i=0;i<256;i++){
if(cnt[i>>2][i%4]>=4){
cnt[i>>2][i%4]-=4;
rev[i>>6]=0;
rev[(i%64)>>4]=1;
rev[(i%16)>>2]=2;
rev[i%4]=3;
}
}
for(int i=0;i<n2;i++){
for(int j=0;j<4;j++) M2[i]+=rev[cnt[i][j]]*(1<<(j<<1));
output(M2[i]);
}
//printf("de\n"); for(int i=0;i<n2;i++) printf("%d ",M2[i]); printf("\n");
}
void decode(int N, int L, int _X[]){
n2=N; l=L;
for(int i=0;i<l;i++) X[i]=_X[i];
for(int i=0;i<n2;i++) M2[i]=0;
de_solve45(); return;
if(n2<=16) de_solve123();
else de_solve45();
}