이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
using namespace std;
const int BASE = 3333;
const int LEN = 64 * 5;
struct BIGNUM {
vector<int> d;
}dp[LEN][256];
BIGNUM add(const BIGNUM& A, const BIGNUM& B) {
BIGNUM res;
int C = 0;
for(int i = 0; i < max((int)A.d.size(), (int)B.d.size()) || C; ++i) {
int cur = C;
if(i < (int)A.d.size()) cur += A.d[i];
if(i < (int)B.d.size()) cur += B.d[i];
C = cur >= BASE;
if(C) cur -= BASE;
res.d.push_back(cur);
}
return res;
}
BIGNUM sub(BIGNUM A, const BIGNUM& B) {
int C = 0;
for(int i = 0; i < (int)B.d.size() || C; ++i) {
A.d[i] -= C + (i < (int)B.d.size() ? B.d[i] : 0);
C = A.d[i] < 0;
if(C) A.d[i] += BASE;
}
while((int)A.d.size() && A.d.back() == 0) A.d.pop_back();
return A;
}
BIGNUM mul(const int& A, const BIGNUM& B) {
BIGNUM res;
int C = 0;
for(int i = 0; i < (int)B.d.size() || C; ++i) {
int cur = C;
if(i < (int)B.d.size()) cur += A * B.d[i];
C = cur / BASE;
res.d.push_back(cur - C * BASE);
}
return res;
}
bool cmp(const BIGNUM& A, const BIGNUM& B) {
if((int)A.d.size() != (int)B.d.size()) return (int)A.d.size() < (int)B.d.size();
for(int i = (int)A.d.size(); i >= 0; ++i) {
if(A.d[i] != B.d[i]) return A.d[i] < B.d[i];
}
return 0;
}
void encode(int N, int M[]) {
for(int i = 0; i < 256; ++i) dp[0][i].d = {1};// ONE
for(int i = 1; i < LEN; ++i) dp[i][0].d = {1};// ONE
for(int i = 1; i < LEN; ++i) {
for(int j = 1; j < 256; ++j) {
dp[i][j] = add(dp[i][j - 1], dp[i - 1][j]);
}
}
BIGNUM val, pwi;
pwi.d = {1};
for(int i = 0; i < N; ++i) {
val = add(val, mul(M[i], pwi));
if(i + 1 < N) pwi = mul(256, pwi);
}
for(int i = LEN - 1; i >= 0; --i) {
int L = 0, R = 255;
while(L < R) {
int M = (L + R) / 2;
if(cmp(dp[i][M], val)) {
L = M + 1;
} else {
R = M;
}
}
send(L);
if(L) val = sub(val, dp[i][L - 1]);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
using namespace std;
const int BASE = 256;
int LEN;
struct BIGNUM {
vector<int> d;
}dp[5 * 64][256];
BIGNUM add(const BIGNUM& A, const BIGNUM& B) {
BIGNUM res;
int C = 0;
for(int i = 0; i < max((int)A.d.size(), (int)B.d.size()) || C; ++i) {
int cur = C;
if(i < (int)A.d.size()) cur += A.d[i];
if(i < (int)B.d.size()) cur += B.d[i];
C = cur >= BASE;
if(C) cur -= BASE;
res.d.push_back(cur);
}
return res;
}
BIGNUM sub(BIGNUM A, const BIGNUM& B) {
int C = 0;
for(int i = 0; i < (int)B.d.size() || C; ++i) {
A.d[i] -= C + (i < (int)B.d.size() ? B.d[i] : 0);
C = A.d[i] < 0;
if(C) A.d[i] += BASE;
}
while((int)A.d.size() && A.d.back() == 0) A.d.pop_back();
return A;
}
BIGNUM mul(const int& A, const BIGNUM& B) {
BIGNUM res;
int C = 0;
for(int i = 0; i < (int)B.d.size() || C; ++i) {
int cur = C;
if(i < (int)B.d.size()) cur += A * B.d[i];
C = cur / BASE;
res.d.push_back(cur - C * BASE);
}
return res;
}
bool cmp(const BIGNUM& A, const BIGNUM& B) {
if((int)A.d.size() != (int)B.d.size()) return (int)A.d.size() < (int)B.d.size();
for(int i = (int)A.d.size(); i >= 0; ++i) {
if(A.d[i] != B.d[i]) return A.d[i] < B.d[i];
}
return 0;
}
void decode(int N, int L, int X[]) {
LEN = 5 * N;
sort(X, X + L);
for(int i = 0; i < 256; ++i) dp[0][i].d = {1};// ONE
for(int i = 1; i < LEN; ++i) dp[i][0].d = {1};// ONE
for(int i = 1; i < LEN; ++i) {
for(int j = 1; j < 256; ++j) {
dp[i][j] = add(dp[i][j - 1], dp[i - 1][j]);
}
}
BIGNUM val;
for(int i = LEN - 1; i >= 0; --i) {
if(X[i]) val = add(val, dp[i][X[i] - 1]);
}
for(int i = 0; i < N; ++i) {
output(val.d[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... |