#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 = 10000, A = 30;
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) {
assert(i + 1 < A);
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] *= b;
dig[i] += 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 < 10; i++) {
out << a.dig[i];
if(i + 1 < A) out << ", ";
}
out << ';';
}
};
void encode(int n, int a[]) {
bigNum val(0);
vector<bigNum> pw(1, 1);
for(int i = 1; i < n; i++) {
pw.pb(pw.back() * 256);
}
for(int i = 0; i < n; i++) {
val += pw[i] * a[i];
}
int len = n * 5;
vector<vector<bigNum>> dp(len + 1, vector<bigNum>(256, 0));
// dp[0] = vector<bigNum>(256, 1);
dp[0][0] = 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; 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 = 10000, A = 30;
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 < 10; 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);
dp[0][0] = 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[i]; j++) {
val += dp[i + 1][j];
}
}
// cout << val << " val here\n";
vector<bigNum> pw(1, 1);
for(int i = 1; i < n; i++) {
pw.pb(pw.back() * 256);
}
// for(int i = 0; i < n; i++) {
// cout << pw[i] << '\n';
// }
// cout << '\n';
for(int i = n - 1; i >= 0; i--) {
// cout << val << '\n';
int ans = 0;
while(pw[i] < val || pw[i] == val) {
ans++;
val -= pw[i];
}
ret.pb(ans);
}
reverse(all(ret));
for(int x : ret) {
// cout << x << ' ';
output(x);
}
// cout << '\n';
}
Compilation message
encoder.cpp: In function 'std::ostream& operator<<(std::ostream&, const bigNum&)':
encoder.cpp:95:2: warning: no return statement in function returning non-void [-Wreturn-type]
95 | }
| ^
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 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
3388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
3668 KB |
Output is correct |
2 |
Correct |
152 ms |
4468 KB |
Output is correct |
3 |
Correct |
210 ms |
5768 KB |
Output is correct |
4 |
Correct |
230 ms |
6136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
3548 KB |
Output is correct |
2 |
Correct |
153 ms |
4668 KB |
Output is correct |
3 |
Correct |
212 ms |
5984 KB |
Output is correct |
4 |
Correct |
227 ms |
6028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
3776 KB |
Output is correct |
2 |
Correct |
229 ms |
6032 KB |
Output is correct |
3 |
Correct |
289 ms |
7280 KB |
Output is correct |
4 |
Correct |
457 ms |
10340 KB |
Output is correct |
5 |
Correct |
464 ms |
10596 KB |
Output is correct |
6 |
Correct |
499 ms |
11008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
228 ms |
6044 KB |
Output is correct - P = 5.000000 |
2 |
Correct |
491 ms |
10904 KB |
Output is correct - P = 5.000000 |
3 |
Correct |
507 ms |
11272 KB |
Output is correct - P = 5.000000 |
4 |
Incorrect |
430 ms |
16296 KB |
Error : Output is wrong |
5 |
Incorrect |
509 ms |
19272 KB |
Error : Output is wrong |
6 |
Incorrect |
537 ms |
20324 KB |
Error : Output is wrong |
7 |
Incorrect |
545 ms |
20712 KB |
Error : Output is wrong |