이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void encode(int N, int M[]) {
int P3[] = {0, 1, 3, 9, 27, 2, 4, 6, 10, 12,
18, 28, 30, 36, 54, 5, 7, 11, 13, 15, 19,
21, 29, 31, 33, 37, 39, 45, 55, 57, 63, 8,
14, 16, 20, 22, 24, 32, 34, 38, 40, 42, 46,
48, 56, 58, 60, 64, 66, 72, 17, 23, 25, 35,
41, 43, 47, 49, 51, 59, 61, 65, 67, 69};
int A[81], P2[64];
if (N == 1) return send(M[0]);
if (N > 43) {
for (int i = 0; i < N; i++) {
A[P3[i]] = M[i]; send(M[i]);
send(M[i]); send(M[i]);
}
sort(P3, P3 + N, [&](int i, int j) {
return A[i] < A[j];
});
for (int i = 0; i + 1 < N; i++) {
int x = P3[i];
for (int j = 0; j < 4; j++) {
int y = x % 3;
while (y--) send(i * 4 + j);
x /= 3;
}
}
} else {
int l = 0; while ((1 << l) < N) l++;
iota(P2, P2 + (1 << l), 0);
sort(P2, P2 + (1 << l), [](int i, int j) {
return __builtin_popcount(i)
< __builtin_popcount(j);
});
for (int i = 0; i < N; i++) {
A[P2[i]] = M[i];
send(M[i]); send(M[i]);
}
sort(P2, P2 + N, [&](int i, int j) {
return A[i] < A[j];
});
for (int i = 0; i + 1 < N; i++) {
int x = P2[i];
for (int j = 0; j < l; j++) {
if (x & 1) send(i * l + j);
x >>= 1;
}
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
void decode(int N, int L, int X[]) {
int P3[] = {0, 1, 3, 9, 27, 2, 4, 6, 10, 12,
18, 28, 30, 36, 54, 5, 7, 11, 13, 15, 19,
21, 29, 31, 33, 37, 39, 45, 55, 57, 63, 8,
14, 16, 20, 22, 24, 32, 34, 38, 40, 42, 46,
48, 56, 58, 60, 64, 66, 72, 17, 23, 25, 35,
41, 43, 47, 49, 51, 59, 61, 65, 67, 69};
int A[81], C[256], M[64], P2[64];
memset(A, -1, sizeof A);
memset(C, 0, sizeof C);
if (N == 1) return output(X[0]);
for (int i = 0; i < L; i++) C[X[i]]++;
if (N > 43) {
for (int i = 0, j = 0; i < 256; i++) {
int x = C[i] / 3;
while (x--) M[j++] = i;
}
for (int i = 0; i + 1 < N; i++) {
int x = 0;
for (int j = 3; j >= 0; j--)
x = x * 3 + C[i * 4 + j] % 3;
A[x] = M[i];
}
for (int i = 0; i < N; i++)
if (A[P3[i]] >= 0)
output(A[P3[i]]);
else output(M[N - 1]);
} else {
int l = 0; while ((1 << l) < N) l++;
iota(P2, P2 + (1 << l), 0);
sort(P2, P2 + (1 << l), [](int i, int j) {
return __builtin_popcount(i)
< __builtin_popcount(j);
});
for (int i = 0, j = 0; i < 256; i++) {
int x = C[i] >> 1;
while (x--) M[j++] = i;
}
for (int i = 0; i + 1 < N; i++) {
int x = 0;
for (int j = l - 1; j >= 0; j--)
x = (x << 1) + (C[i * l + j] & 1);
A[x] = M[i];
}
for (int i = 0; i < N; i++)
if (A[P2[i]] >= 0)
output(A[P2[i]]);
else output(M[N - 1]);
}
}
# | 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... |