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>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int dpp[9][15];
vector<int>koduj(int x) {
int dlu=0;
while(dpp[8][dlu]<=x) {
x-=dpp[8][dlu];
++dlu;
}
vector<int>ans(8);
int c=8;
while(dlu>0 && c>0) {
if(c==1) {
++ans[0];
--dlu;
continue;
}
if(dpp[c-1][dlu]<=x) {
x-=dpp[c-1][dlu];
++ans[c-1];
--dlu;
} else --c;
}
return ans;
}
void encode(int n, int _T[]) {
dpp[1][0]=1;
for(int x=1; x<=8; ++x) {
for(int y=1; y<=14; ++y) dpp[x][y]=dpp[x-1][y]+dpp[x][y-1];
}
vector<int>T(n);
rep(i, n) T[i]=_T[i];
if(n%2==1) T.pb(0);
rep(i, (n+1)/2) {
vector<int>P=koduj(T[2*i]+256*T[2*i+1]);
rep(j, 8) rep(l, P[j]) send(8*i+j);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
int dp[9][15];
int odkoduj(vector<int>T) {
int x=0, sum=0;
rep(i, 8) sum+=T[i];
rep(i, sum) x+=dp[8][i];
rep(i, 7) {
rep(j, T[7-i]) {
x+=dp[7-i][sum];
--sum;
}
}
return x;
}
void decode(int n, int l, int _T[]) {
dp[0][1]=1;
for(int x=1; x<=8; ++x) {
for(int y=1; y<=14; ++y) dp[x][y]=dp[x-1][y]+dp[x][y-1];
}
vector<int>T(256);
rep(i, l) ++T[_T[i]];
vector<int>ans(n+1);
rep(i, (n+1)/2) {
vector<int>P(8);
rep(j, 8) P[j]=T[8*i+j];
int x=odkoduj(P);
ans[2*i]=x%256;
ans[2*i+1]=x/256;
}
rep(i, n) output(ans[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |