#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define sz(v) (int)v.size()
int ativo(int x, int p){
if(x & (1<<p))return 1;
return 0;
}
void encode(int n, int m[])
{
map<int,int> freq, v;
for(int p = 0; p < 8; p++){
for(int i = 0; i < n; i+=2){
int x = (ativo(m[i], p)<<1);
if(i+1 < n)x += ativo(m[i+1], p);
freq[x]++;
}
}
vector< pair<int,int> > o;
for(auto it : freq)o.emplace_back(it.sc, it.fi);
sort(o.begin(),o.end(),greater<pair<int,int>>());
for(int i = 0; i < sz(o); i++)v[o[i].sc] = i;
for(int p = 0; p < 8; p++){
int g = 0;
for(int i = 0; i < n; i+=2){
int x = (ativo(m[i], p)<<1);
if(i+1 < n)x += ativo(m[i+1], p);
int val = (p<<5) + g;
for(int j = 0; j < v[x]; j++)send(val);
g++;
}
}
vector<int> a = {0,1,2,3};
int ans = 0;
do{
int parar = 1;
for(int i = 0; i < sz(o); i++)
if(a[i] != o[i].sc){parar = 0; break;}
if(parar){
for(int i = 0; i < 4; i++)send(ans);
break;
}
ans++;
}while(next_permutation(a.begin(),a.end()));
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
static int v[70];
static map<int,int> freq;
#define fi first
#define sc second
void decode(int n, int l, int x[])
{
for(int i = 0; i < n; i++)v[i] = 0;
freq.clear();
for(int i = 0; i < l; i++)freq[x[i]]++;
int qtd = 0;
auto it = freq.begin();
while(it != freq.end()){
if(it->sc >= 4){
qtd = it->fi;
freq[it->fi] -= 4;
break;
}
it++;
}
vector<int> a = {0,1,2,3};
int cur = 0;
do{
if(cur == qtd)break;
cur++;
}while(next_permutation(a.begin(),a.end()));
for(int i = 0; i < l; i++){
if(freq[x[i]] == 0)continue;
int f = a[freq[x[i]]]; freq[x[i]] = 0;
int g = x[i]%32; x[i]/=32;
int p = x[i];
if(f & 2)v[g*2] += (1<<p);
if(f & 1)v[g*2+1] += (1<<p);
}
for(int i = 0; i < n; i++)output(v[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... |