#include "encoder.h"
#include "encoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
//#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int B = 321, A = 340;
struct bigNum {
array<int, A> dig;
bigNum(int x = 0) {
for(int i = 0; i < A; i++) {
dig[i] = x % B;
x /= B;
}
}
bigNum& operator+=(const bigNum &b) {
int carry = 0;
for(int i = 0; i < A; i++) {
dig[i] += b.dig[i] + carry;
carry = dig[i] / B;
dig[i] %= B;
}
return *this;
};
bigNum& operator-=(const bigNum &b) {
for(int i = 0; i < A; i++) {
dig[i] -= b.dig[i];
while(dig[i] < 0) {
dig[i] += B;
dig[i + 1]--;
}
}
return *this;
}
bigNum& operator*=(const int &b) {
int carry = 0;
for(int i = 0; i < A; i++) {
dig[i] = dig[i] * b + carry;
carry = dig[i] / B;
dig[i] %= B;
}
return *this;
}
friend bigNum operator+(const bigNum &a, const bigNum &b) {
return bigNum(a) += b;
}
friend bigNum operator-(const bigNum &a, const bigNum &b) {
return bigNum(a) -= b;
}
friend bigNum operator*(const bigNum &a, const int &b) {
return bigNum(a) *= b;
}
int compare(const bigNum &a) {
for(int i = A - 1; i >= 0; i--) {
if(a.dig[i] > dig[i]) return -1;
else if(a.dig[i] < dig[i]) return 1;
}
return 0;
}
bool operator<(const bigNum &b) {
return this->compare(b) == -1;
}
bool operator>(const bigNum &b) {
return this->compare(b) == 1;
}
bool operator==(const bigNum &b) {
return this->compare(b) == 0;
}
bool operator!=(const bigNum &b) {
return this->compare(b) != 0;
}
friend ostream& operator<<(ostream& out, const bigNum &a) {
for(int i = 0; i < A; i++) {
out << a.dig[i];
if(i + 1 < A) out << ", ";
}
out << ';';
}
};
void encode(int n, int a[]) {
bigNum val(0);
for(int i = 0; i < n; i++) {
val = val * 256 + a[i];
}
int len = n * 5;
vector<vector<bigNum>> dp(len + 1, vector<bigNum>(256, 0));
dp[0] = vector<bigNum>(256, 1);
for(int i = 1; i <= len; i++) {
for(int j = 0; j < 256; j++) {
dp[i][j] = dp[i - 1][j];
if(j - 1 >= 0) dp[i][j] += dp[i][j - 1];
}
}
for(int i = len * 5; i >= 1; i--) {
int ans = 0;
for(int j = 0; j < 256; j++) {
if(dp[i][j] > val) {
ans = j;
break;
}
val -= dp[i][j];
}
send(ans);
}
}
#include "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
//#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int B = 321, A = 340;
struct bigNum {
array<int, A> dig;
bigNum(int x = 0) {
for(int i = 0; i < A; i++) {
dig[i] = x % B;
x /= B;
}
}
bigNum& operator+=(const bigNum &b) {
int carry = 0;
for(int i = 0; i < A; i++) {
dig[i] += b.dig[i] + carry;
carry = dig[i] / B;
dig[i] %= B;
}
return *this;
};
bigNum& operator-=(const bigNum &b) {
for(int i = 0; i < A; i++) {
dig[i] -= b.dig[i];
while(dig[i] < 0) {
dig[i] += B;
dig[i + 1]--;
}
}
return *this;
}
bigNum& operator*=(const int &b) {
int carry = 0;
for(int i = 0; i < A; i++) {
dig[i] = dig[i] * b + carry;
carry = dig[i] / B;
dig[i] %= B;
}
return *this;
}
friend bigNum operator+(const bigNum &a, const bigNum &b) {
return bigNum(a) += b;
}
friend bigNum operator-(const bigNum &a, const bigNum &b) {
return bigNum(a) -= b;
}
friend bigNum operator*(const bigNum &a, const int &b) {
return bigNum(a) *= b;
}
int compare(const bigNum &a) {
for(int i = A - 1; i >= 0; i--) {
if(a.dig[i] > dig[i]) return -1;
else if(a.dig[i] < dig[i]) return 1;
}
return 0;
}
bool operator<(const bigNum &b) {
return this->compare(b) == -1;
}
bool operator>(const bigNum &b) {
return this->compare(b) == 1;
}
bool operator==(const bigNum &b) {
return this->compare(b) == 0;
}
bool operator!=(const bigNum &b) {
return this->compare(b) != 0;
}
friend ostream& operator<<(ostream& out, const bigNum &a) {
for(int i = 0; i < A; i++) {
out << a.dig[i];
if(i + 1 < A) out << ", ";
}
out << ';';
}
};
void decode(int n, int l, int x[]) {
sort(x, x + l);
int len = n * 5;
vector<vector<bigNum>> dp(len + 1, vector<bigNum>(256, 0));
dp[0] = vector<bigNum>(256, 1);
for(int i = 1; i <= len; i++) {
for(int j = 0; j < 256; j++) {
dp[i][j] = dp[i - 1][j];
if(j - 1 >= 0) dp[i][j] += dp[i][j - 1];
}
}
vector<int> ret;
bigNum val(0);
for(int i = l - 1; i >= 0; i--) {
for(int j = 0; j < x[l]; j++) {
val += dp[i + 1][j];
}
}
vector<bigNum> pw(1);
for(int i = 1; i < n; i++) {
pw.pb(pw.back() * 256);
}
for(int i = n - 1; i > 1; i--) {
int ans = 0;
while(pw[i] < val) {
ans++;
val -= pw[i];
}
ret.pb(ans);
}
reverse(all(ret));
for(int x : ret) {
output(x);
}
}
Compilation message
encoder.cpp: In function 'std::ostream& operator<<(std::ostream&, const bigNum&)':
encoder.cpp:93:2: warning: no return statement in function returning non-void [-Wreturn-type]
93 | }
| ^
decoder.cpp: In function 'std::ostream& operator<<(std::ostream&, const bigNum&)':
decoder.cpp:93:2: warning: no return statement in function returning non-void [-Wreturn-type]
93 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
29080 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
29056 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
30 ms |
29084 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
29048 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
57 ms |
57064 KB |
Execution killed with signal 11 |
2 |
Runtime error |
125 ms |
112900 KB |
Execution killed with signal 11 |
3 |
Runtime error |
114 ms |
116524 KB |
Execution killed with signal 11 |
4 |
Runtime error |
168 ms |
175796 KB |
Execution killed with signal 11 |
5 |
Runtime error |
211 ms |
210828 KB |
Execution killed with signal 11 |
6 |
Runtime error |
210 ms |
221196 KB |
Execution killed with signal 11 |
7 |
Runtime error |
217 ms |
224772 KB |
Execution killed with signal 11 |