# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
382674 | jjang36524 | Parrots (IOI11_parrots) | C++14 | 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 "decoder.h"
#include "decoderlib.h"
#include <stdlib.h>
#include <string.h>
#define DIGIT 65536
#include <algorithm>
using namespace std;
struct bigint
{
int arr[100];
bigint()
{
memset(arr,0,sizeof(arr));
}
};
bigint plu(bigint a,bigint b)
{
bigint ans;
int i;
for(i=0;i<99;i++)
{
int c=a.arr[i]+b.arr[i];
ans.arr[i+1]+=c>>16;
ans.arr[i]+=c&(65535);
}
return ans;
}
bigint minu(bigint a,bigint b)
{
bigint ans;
int i;
for(i=0;i<100;i++)
{
while(a.arr[i]<b.arr[i])
{
a.arr[i]+=DIGIT;
a.arr[i+1]--;
}
ans.arr[i]=a.arr[i]-b.arr[i];
}
return ans;
}
bool cmp(bigint a,bigint b)
{
bigint ans;
int i;
for(i=99;i>=0;i--)
{
if(a.arr[i]!=b.arr[i])
{
return a.arr[i]>b.arr[i];
}
}
return 1;
}
void encode(int N, int M[])
{
static bigint comb[600][600];
int i,j;
for(i=0;i<600;i++)
{
comb[i][0].arr[0]=1;
}
for(i=1;i<600;i++)
{
for(j=1;j<=i;j++)
{
comb[i][j]=plu(comb[i-1][j],comb[i-1][j-1]);
}
}
bigint mul=comb[0][0];
bigint an;
for(i=0;i<N;i++)
{
for(j=0;j<M[i];j++)
{
an=plu(an,mul);
}
for(j=0;j<8;j++)
{
mul=plu(mul,mul);
}
}
int K=5*N;
int c=0;
for(i=0;i<K;i++)
{
while(c<255&&cmp(an,comb[256-c+(K-i-1)-1][K-i-1]))
{
an=minu(an,comb[256-c+(K-i-1)-1][K-i-1]);
c++;
}
send(c);
}
}
#include "encoder.h"
#include "encoderlib.h"
#include "decoder.h"
#include "decoderlib.h"
#include <stdlib.h>
#include <string.h>
#define DIGIT 65536
#include <algorithm>
using namespace std;
struct bigint
{
int arr[100];
bigint()
{
memset(arr,0,sizeof(arr));
}
};
bigint plu(bigint a,bigint b)
{
bigint ans;
int i;
for(i=0;i<99;i++)
{
int c=a.arr[i]+b.arr[i];
ans.arr[i+1]+=c>>16;
ans.arr[i]+=c&(65535);
}
return ans;
}
bigint minu(bigint a,bigint b)
{
bigint ans;
int i;
for(i=0;i<100;i++)
{
while(a.arr[i]<b.arr[i])
{
a.arr[i]+=DIGIT;
a.arr[i+1]--;
}
ans.arr[i]=a.arr[i]-b.arr[i];
}
return ans;
}
bool cmp(bigint a,bigint b)
{
bigint ans;
int i;
for(i=99;i>=0;i--)
{
if(a.arr[i]!=b.arr[i])
{
return a.arr[i]>b.arr[i];
}
}
return 1;
}
void encode(int N, int M[])
{
static bigint comb[600][600];
int i,j;
for(i=0;i<600;i++)
{
comb[i][0].arr[0]=1;
}
for(i=1;i<600;i++)
{
for(j=1;j<=i;j++)
{
comb[i][j]=plu(comb[i-1][j],comb[i-1][j-1]);
}
}
bigint mul=comb[0][0];
bigint an;
for(i=0;i<N;i++)
{
for(j=0;j<M[i];j++)
{
an=plu(an,mul);
}
for(j=0;j<8;j++)
{
mul=plu(mul,mul);
}
}
int K=5*N;
int c=0;
for(i=0;i<K;i++)
{
while(c<255&&cmp(an,comb[256-c+(K-i-1)-1][K-i-1]))
{
an=minu(an,comb[256-c+(K-i-1)-1][K-i-1]);
c++;
}
send(c);
}
}