이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
int nxt() {
int t;
cin >> t;
return t;
}
int dp[17][20];
vector<int> encode(int x) {
vector<int> res(20);
for (int j = 19; j >= 0; --j) {
for (int i = 0; i < 17; ++i) {
if (x - dp[i][j] < 0) {
res[j] = i;
break;
}
x -= dp[i][j];
}
}
while (res.back() == 16) res.pop_back();
return res;
}
void encode(int32_t n, int32_t vc[]) {memset(dp,0,sizeof dp);
for (int i = 0; i < 17; ++i) dp[i][0] = 1;
for (int j = 1; j < 20; ++j) {
for (int i = 0; i < 17; ++i) {
for (int k = 0; k <= i; ++k) {
dp[i][j] += dp[k][j - 1];
}
}
}
vector<int> v(vc, vc+n);
while (n % 4) {
v.push_back(0);
++n;
}
vector<int> ans;
for (int i = 0; i < n; i += 4) {
auto x = encode((v[i] << 24) + (v[i + 1] << 16) + (v[i + 2] << 8) + v[i + 3]);
for (int j : x) ans.push_back(((i / 4) << 4) + j);
}
for (int i : ans) send(i);
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
int nxt() {
int t;
cin >> t;
return t;
}
int dp[17][20];
int decode(vector<int> x) {
sort(all(x));
while (x.size() < 20) x.push_back(16);
int res = 0;
for (int j = 0; j < 20; ++j) {
for (int i = 1; i < 17; ++i) {
if (x[j] >= i) res += dp[i - 1][j];
}
}
return res;
}
void decode(int32_t n, int32_t m, int32_t vc[]) {memset(dp, 0,sizeof dp);
for (int i = 0; i < 17; ++i) dp[i][0] = 1;
for (int j = 1; j < 20; ++j) {
for (int i = 0; i < 17; ++i) {
for (int k = 0; k <= i; ++k) {
dp[i][j] += dp[k][j - 1];
}
}
}
vector<int> u[16];
for (int j = 0; j < m; ++j) {
int i = vc[j];
int idx = i >> 4;
u[idx].push_back(i & 15);
}
vector<int> ans;
for (auto x : u) { // n!
if (x.empty()) continue;
int y = decode(x);
ans.push_back(y >> 24);
ans.push_back(y >> 16 & 255);
ans.push_back(y >> 8 & 255);
ans.push_back(y & 255);
}
for (int i = 0; i < n; ++i) output(ans[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... |