#include "encoder.h"
#include "encoderlib.h"
#include <stdio.h>
#include <algorithm>
using namespace std;
// 256 H 261 > 256^64
int Ht[260][270][70];
int cntt[260][270];
int first;
int tmpt[70];
#define MOD 256
void sett(){
int i,j,k;
for(i=1; i<=256; i++){ cntt[i][0] = 1; Ht[i][0][1] = 1; }
for(i=1; i<=256; i++){ cntt[i][1] = 1; Ht[i][1][1] = i; }
for(i=1; i<=262; i++){ cntt[1][i] = 1; Ht[1][i][1] = 1; }
for(i=2; i<=256; i++){
for(j=2; j<=262; j++){
for(k=1; k<=cntt[i][j-1]; k++) Ht[i][j][k] = Ht[i][j-1][k];
for(k=1; k<=cntt[i-1][j]; k++) Ht[i][j][k] += Ht[i-1][j][k];
for(k=1; k<=max(cntt[i][j-1],cntt[i-1][j]); k++){
Ht[i][j][k+1] += (Ht[i][j][k] / MOD);
Ht[i][j][k] %= MOD;
}
for(k=max(cntt[i][j-1],cntt[i-1][j])+1; ; k++){
if(Ht[i][j][k] == 0) break;
Ht[i][j][k+1] = (Ht[i][j][k] / MOD);
Ht[i][j][k] %= MOD;
}
cntt[i][j] = k-1;
}
}
}
int comp(int n,int m,int len){
if(cntt[n][m] > len) return -1;
if(cntt[n][m] < len) return 1;
int i;
for(i=cntt[n][m]; i>=1; i--){
if(Ht[n][m][i] > tmpt[i]) return -1;
if(Ht[n][m][i] < tmpt[i]) return 1;
}
return 0;
}
void encode(int N, int M[]){
int i,j,k;
int x,sum,len;
first++;
if(first == 1) sett();
len = N;
for(i=1; i<=N; i++) tmpt[i] = 255;
for(i=1; ; i++){
if(comp(256,i,len) <= 0) break;
}
x = sum = i;
for(i=0; i<N; i++) tmpt[i+1] = M[i];
len = N;
for(i=N; i>=1; i--){
if(tmpt[i] != 0) break;
}
len = i;
for(i=256; i>=2; i--){
for(j=0; j<=x; j++){
if(comp(i-1,x-j,len) < 0) break;
for(k=1; k<=cntt[i-1][x-j]; k++){
tmpt[k] -= Ht[i-1][x-j][k];
if(tmpt[k] < 0){
tmpt[k] += MOD;
tmpt[k+1]--;
}
}
for(k=cntt[i][j]+1; k<=len; k++){
if(tmpt[k] < 0){
tmpt[k] += MOD;
tmpt[k+1]--;
}else break;
}
for(k=len; k>=1; k--){
if(tmpt[k] != 0) break;
}
len = k;
}
for(k=0; k<j; k++) send(i-1);
x -= j;
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int H[260][270][70];
int cnt[260][270];
int tmp[70];
#define MOD 256
void setting(){
int i,j,k;
for(i=1; i<=256; i++){ cnt[i][0] = 1; H[i][0][1] = 1; }
for(i=1; i<=256; i++){ cnt[i][1] = 1; H[i][1][1] = i; }
for(i=1; i<=262; i++){ cnt[1][i] = 1; H[1][i][1] = 1; }
for(i=2; i<=256; i++){
for(j=2; j<=262; j++){
for(k=1; k<=cnt[i][j-1]; k++) H[i][j][k] = H[i][j-1][k];
for(k=1; k<=cnt[i-1][j]; k++) H[i][j][k] += H[i-1][j][k];
for(k=1; k<=max(cnt[i][j-1],cnt[i-1][j]); k++){
H[i][j][k+1] += (H[i][j][k] / MOD);
H[i][j][k] %= MOD;
}
for(k=max(cnt[i][j-1],cnt[i-1][j])+1; ; k++){
if(H[i][j][k] == 0) break;
H[i][j][k+1] = (H[i][j][k] / MOD);
H[i][j][k] %= MOD;
}
cnt[i][j] = k-1;
}
}
}
int compare(int n,int m,int len){
if(cnt[n][m] > len) return -1;
if(cnt[n][m] < len) return 1;
int i;
for(i=cnt[n][m]; i>=1; i--){
if(H[n][m][i] > tmp[i]) return -1;
if(H[n][m][i] < tmp[i]) return 1;
}
return 0;
}
int firsttime;
int many[260];
int ans[100];
void decode(int N, int L, int X[]){
int i,j,k;
int x,sum,len;
firsttime++;
if(firsttime == 1) setting();
for(i=1; i<=N; i++) tmp[i] = 255;
len = N;
for(i=1; i<=262; i++){
if(compare(256,i,len) <= 0) break;
}
x = sum = i;
for(i=0; i<256; i++) many[i] = 0;
for(i=0; i<L; i++) many[X[i]]++;
for(i=1; i<=N; i++) ans[i] = 0;
for(i=255; i>=1; i--){
for(j=0; j<many[i]; j++){
for(k=1; k<=cnt[i][x-j]; k++){
ans[k] += H[i][x-j][k];
}
}
x -= many[i];
}
for(k=1; k<N; k++){
ans[k+1] += (ans[k]/256);
ans[k] %= 256;
}
for(k=1; k<=N; k++) output(ans[k]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
39216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
40112 KB |
Output is correct |
2 |
Correct |
50 ms |
40352 KB |
Output is correct |
3 |
Correct |
59 ms |
40640 KB |
Output is correct |
4 |
Correct |
52 ms |
40640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
40640 KB |
Output is correct |
2 |
Correct |
51 ms |
40680 KB |
Output is correct |
3 |
Correct |
50 ms |
40680 KB |
Output is correct |
4 |
Correct |
53 ms |
40680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
40680 KB |
Output is correct |
2 |
Correct |
59 ms |
40896 KB |
Output is correct |
3 |
Correct |
51 ms |
40896 KB |
Output is correct |
4 |
Correct |
52 ms |
40896 KB |
Output is correct |
5 |
Correct |
52 ms |
40896 KB |
Output is correct |
6 |
Correct |
53 ms |
40896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
40896 KB |
Output is correct - P = 1.750000 |
2 |
Correct |
52 ms |
40896 KB |
Output is correct - P = 2.437500 |
3 |
Correct |
56 ms |
40896 KB |
Output is correct - P = 2.484848 |
4 |
Correct |
56 ms |
40896 KB |
Output is correct - P = 3.300000 |
5 |
Correct |
57 ms |
40896 KB |
Output is correct - P = 3.850000 |
6 |
Correct |
69 ms |
40896 KB |
Output is correct - P = 4.031746 |
7 |
Correct |
61 ms |
40896 KB |
Output is correct - P = 4.093750 |