This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int MA = 16, P = 20;
ll dp[P][MA+1];
bool activated = false;
ll go(int digit, int layer){
if (digit == P) return 1;
if (dp[digit][layer] != -1) return dp[digit][layer];
ll ans = 0;
for(int j = layer; j <= MA; ++j) ans += go(digit + 1, j);
return dp[digit][layer] = ans;
}
vector<int> get_state(ll x){
x++;
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
vector<int> ans;
int layer = 0;
for(int i = 0; i < P; ++i) {
for(int j = layer; j <= MA; ++j){
ll cur = go(i + 1, j);
if (cur < x) {
x -= cur;
}
else{
layer = j;
break;
}
}
if (layer > 0) ans.push_back(layer-1);
}
return ans;
}
ll get_order(vector<int> state){
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
ll ans = 0;
for(int &i: state)i++;
while(state.size() < P) state.insert(state.begin(), 0);
int layer = 0;
for(int i = 0; i < P; ++i){
for(int j = layer; j < state[i]; ++j){
int cur = go(i + 1, j);
ans += cur;
}
layer = state[i];
}
return ans;
}
void encode(int N, int M[]){
vector<ll> a((N + 3) / 4);
for(int i= 0; i< N; ++i){
a[i / 4] += M[i] * MASK((i % 4) * 8);
}
for(int i = 0; i < a.size(); ++i){
vector<int> state = get_state(a[i]);
for(int j: state) send(j + MA * i);
}
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int MA = 16, P = 20;
ll dp[P][MA+1];
bool activated = false;
ll go(int digit, int layer){
if (digit == P) return 1;
if (dp[digit][layer] != -1) return dp[digit][layer];
ll ans = 0;
for(int j = layer; j <= MA; ++j) ans += go(digit + 1, j);
return dp[digit][layer] = ans;
}
vector<int> get_state(ll x){
x++;
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
vector<int> ans;
int layer = 0;
for(int i = 0; i < P; ++i) {
for(int j = layer; j <= MA; ++j){
ll cur = go(i + 1, j);
if (cur < x) {
x -= cur;
}
else{
layer = j;
break;
}
}
if (layer > 0) ans.push_back(layer-1);
}
return ans;
}
ll get_order(vector<int> state){
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
ll ans = 0;
for(int &i: state)i++;
while(state.size() < P) state.insert(state.begin(), 0);
int layer = 0;
for(int i = 0; i < P; ++i){
for(int j = layer; j < state[i]; ++j){
ll cur = go(i + 1, j);
ans += cur;
}
layer = state[i];
}
return ans;
}
void decode(int N, int L, int X[]){
vector<int> ans(N + 4);
vector<vector<int>> cur((N + 3) / 4);
for(int i = 0; i < L; ++i){
cur[X[i] / 16].push_back(X[i]);
}
for(int i = 0; i < cur.size(); ++i){
sort(ALL(cur[i]));
for(int &j: cur[i]) j -= i * MA;
ll idx = get_order(cur[i]);
ans[i * 4] = idx % MASK(8);
ans[i * 4 + 1] = (idx / MASK(8)) % MASK(8);
ans[i * 4 + 2] = (idx / MASK(16)) % MASK(8);
ans[i * 4 + 3] = (idx / MASK(24)) % MASK(8);
}
while(ans.size() > N) ans.pop_back();
for(int i: ans) output(i);
}
Compilation message (stderr)
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:119:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for(int i = 0; i < a.size(); ++i){
| ~~^~~~~~~~~~
decoder.cpp: In function 'void decode(int, int, int*)':
decoder.cpp:121:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for(int i = 0; i < cur.size(); ++i){
| ~~^~~~~~~~~~~~
decoder.cpp:131:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
131 | while(ans.size() > N) ans.pop_back();
| ~~~~~~~~~~~^~~
# | 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... |