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<bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N = 1e5 + 10;
vi find_kth(ll k, int d, ll C[][42])
{
vi ans;
int s = d * 5;
for (int i = 0 ; i < 16; ++i)
while (k >= C[15 - i][s + 15 - i]) k -= C[15 - i][s + 15 - i], s--, ans.eb(i);
return ans;
}
void encode(int n, int M[])
{
ll C[42][42];
memset(C, 0, sizeof(C));
for (int i = 0; i <= 40; ++i)
{
C[0][i] = 1;
for (int j = 1 ; j <= i; ++j) C[j][i] = C[j - 1][i - 1] + C[j][i - 1];
}
for (int i = 0; i < n; i += 4)
{
ll s = 0;
int d = 0;
for (int j = i; j < min(n, i + 4); ++j) d++, s = (s << 8) + M[j];
vi vt = find_kth(s, d, C);
for (int x : vt) send((x << 4) + (i / 4));
}
}
//int main() {}
#include<bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
const int N = 1e5 + 10;
ll find_order(int cnt[], int d, ll C[][42])
{
ll k = 0;
int s = d * 5;
for (int i = 0 ; i < 16; ++i)
for (int j = 0 ; j < cnt[i]; ++j) k += C[15 - i][s + 15 - i], s--;
return k;
}
void decode(int n, int L, int X[])
{
ll C[42][42];
memset(C, 0, sizeof(C));
for (int i = 0; i <= 40; ++i)
{
C[0][i] = 1;
for (int j = 1 ; j <= i; ++j) C[j][i] = C[j - 1][i - 1] + C[j][i - 1];
}
int a[20][20];
memset(a, 0, sizeof(a));
for (int i = 0; i < L; ++i) a[X[i] & 15][X[i] >> 4]++;
for (int i = 0; i < n; i += 4)
{
int d = min(4, n - i), id = i / 4;
ll k = find_order(a[id], d, C);
vi vt;
for (int j = 0; j < d; ++j) vt.eb(k & 255), k >>= 8;
reverse(all(vt));
for (int x : vt) output(x);
}
}
//int main() {}
# | 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... |