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;
void encode(int N, int M[])
{
vector <int> p;
for(int i = 0; i < 4; i++) p.push_back(i);
map <vector <int>, int> mp;
int id = 0;
do {
mp[p] = id++;
} while(next_permutation(p.begin(), p.end()));
int cnt[4];
memset(cnt, 0, sizeof cnt);
for(int i = 0; i < N; i++) {
int x = M[i];
int p = x % 4;
x /= 4;
int q = x % 4;
x /= 4;
int r = x % 4;
x /= 4;
int s = x % 4;
x /= 4;
cnt[p] += 1;
cnt[q] += 1;
cnt[r] += 1;
cnt[s] += 1;
}
vector <pair <int, int>> v;
for(int i = 0; i < 4; i++) {
v.push_back(make_pair(-cnt[i], i));
}
sort(v.begin(), v.end());
vector <int> perm;
vector <int> rep (4);
for(auto i : v) {
perm.push_back(i.second);
}
for(int i = 0; i < 4; i++) {
rep[perm[i]] = i;
}
for(int i = 0; i < 4; i++) {
send(mp[perm]);
}
int cur = 0;
for(int i = 0; i < N; i++) {
int x = M[i];
int p = rep[x % 4];
x /= 4;
int q = rep[x % 4];
x /= 4;
int r = rep[x % 4];
x /= 4;
int s = rep[x % 4];
x /= 4;
while(p--) send(cur);
++cur;
while(q--) send(cur);
++cur;
while(r--) send(cur);
++cur;
while(s--) send(cur);
++cur;
}
}
#include "decoder.h"
#include "decoderlib.h"
#include "bits/stdc++.h"
using namespace std;
void decode(int N, int L, int X[])
{
vector <int> p;
vector <vector <int>> ls;
for(int i = 0; i < 4; i++) p.push_back(i);
int id = 0;
do {
ls.push_back(p);
} while(next_permutation(p.begin(), p.end()));
int cnt[300];
memset(cnt, 0, sizeof cnt);
vector <int> perm;
for(int i = 0; i < L; i++) {
cnt[X[i]] += 1;
}
for(int i = 0; i < 4*N; i++) {
if(cnt[i] >= 4) {
perm = ls[i];
cnt[i] -= 4;
}
}
for(int i = 0; i < 4 * N; i += 4) {
output(perm[cnt[i]] + perm[cnt[i+1]] * 4 + perm[cnt[i+2]] * 16 + perm[cnt[i+3]] * 64);
}
}
Compilation message (stderr)
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:11:6: warning: unused variable 'id' [-Wunused-variable]
int id = 0;
^~
# | 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... |