이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
#define encoder
#ifdef tabr
int dat[100];
int id = 0;
void send(int x) {
dat[id++] = x;
}
void output(int x) {
cout << x << '\n';
}
#else
#include "decoder.h"
#include "decoderlib.h"
#include "encoder.h"
#include "encoderlib.h"
#endif
#ifdef encoder
void encode(int n, int a[]) {
vector<vector<int>> w(4);
for (int i = 0; i < (1 << 27); i++) {
int c = __builtin_popcount(i);
if (c % 5 == 0 && c <= 15) {
w[c / 5].emplace_back(i);
}
}
for (int beg = 0; beg < n; beg += 3) {
int c = min(3, n - beg);
int z = 0;
for (int i = beg; i < min(n, beg + 3); i++) {
z *= 256;
z += a[i];
}
int k = w[c][z];
vector<int> b;
int lst = 0;
for (int i = 0; i < c * 5 + 12; i++) {
if (k & (1 << i)) {
b.emplace_back(lst);
} else {
lst++;
}
}
for (int i : b) {
send(i + beg * 4);
}
debug(c);
debug(z);
debug(k);
debug(b);
}
}
#endif
#ifdef decoder
void decode(int n, int l, int a[]) {
vector<vector<int>> w(4);
for (int i = 0; i < (1 << 27); i++) {
int c = __builtin_popcount(i);
if (c % 5 == 0 && c <= 15) {
w[c / 5].emplace_back(i);
}
}
sort(a, a + l);
for (int beg = 0; beg < n; beg += 3) {
int c = min(3, n - beg);
vector<int> b;
for (int i = beg * 5; i < min(n, beg + 3) * 5; i++) {
b.emplace_back(a[i] - beg * 4);
}
int k = 0;
for (int i = 0; i < (int) b.size(); i++) {
k |= 1 << (i + b[i]);
}
int z = (int) (lower_bound(w[c].begin(), w[c].end(), k) - w[c].begin());
debug(c);
debug(b);
debug(k);
debug(z);
b.clear();
for (int i = 0; i < c; i++) {
b.emplace_back(z % 256);
z /= 256;
}
reverse(b.begin(), b.end());
for (int i : b) {
output(i);
}
}
}
#endif
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n = 6;
int a[] = {1, 1, 4, 5, 1, 4};
encode(n, a);
decode(n, id, dat);
return 0;
}
#endif
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
#define decoder
#ifdef tabr
int dat[100];
int id = 0;
void send(int x) {
dat[id++] = x;
}
void output(int x) {
cout << x << '\n';
}
#else
#include "decoder.h"
#include "decoderlib.h"
#include "encoder.h"
#include "encoderlib.h"
#endif
#ifdef encoder
void encode(int n, int a[]) {
vector<vector<int>> w(4);
for (int i = 0; i < (1 << 27); i++) {
int c = __builtin_popcount(i);
if (c % 5 == 0 && c <= 15) {
w[c / 5].emplace_back(i);
}
}
for (int beg = 0; beg < n; beg += 3) {
int c = min(3, n - beg);
int z = 0;
for (int i = beg; i < min(n, beg + 3); i++) {
z *= 256;
z += a[i];
}
int k = w[c][z];
vector<int> b;
int lst = 0;
for (int i = 0; i < c * 5 + 12; i++) {
if (k & (1 << i)) {
b.emplace_back(lst);
} else {
lst++;
}
}
for (int i : b) {
send(i + beg * 4);
}
debug(c);
debug(z);
debug(k);
debug(b);
}
}
#endif
#ifdef decoder
void decode(int n, int l, int a[]) {
vector<vector<int>> w(4);
for (int i = 0; i < (1 << 27); i++) {
int c = __builtin_popcount(i);
if (c % 5 == 0 && c <= 15) {
w[c / 5].emplace_back(i);
}
}
sort(a, a + l);
for (int beg = 0; beg < n; beg += 3) {
int c = min(3, n - beg);
vector<int> b;
for (int i = beg * 5; i < min(n, beg + 3) * 5; i++) {
b.emplace_back(a[i] - beg * 4);
}
int k = 0;
for (int i = 0; i < (int) b.size(); i++) {
k |= 1 << (i + b[i]);
}
int z = (int) (lower_bound(w[c].begin(), w[c].end(), k) - w[c].begin());
debug(c);
debug(b);
debug(k);
debug(z);
b.clear();
for (int i = 0; i < c; i++) {
b.emplace_back(z % 256);
z /= 256;
}
reverse(b.begin(), b.end());
for (int i : b) {
output(i);
}
}
}
#endif
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n = 6;
int a[] = {1, 1, 4, 5, 1, 4};
encode(n, a);
decode(n, id, dat);
return 0;
}
#endif
# | 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... |