이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 12, P = 15;
int dp[P][MA+1];
bool activated = false;
int go(int digit, int layer){
if (digit == P) return 1;
if (dp[digit][layer] != -1) return dp[digit][layer];
int ans = 0;
for(int j = layer; j <= MA; ++j) ans += go(digit + 1, j);
return dp[digit][layer] = ans;
}
vector<int> get_state(int 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){
int cur = go(i + 1, j);
if (cur < x) {
x -= cur;
}
else{
layer = j;
break;
}
}
if (layer > 0) ans.push_back(layer-1);
}
return ans;
}
int get_order(vector<int> state){
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
int 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<int> a((N + 2) / 3);
for(int i= 0; i< N; ++i){
a[i / 3] += M[i] * MASK((i % 3) * 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 = 12, P = 15;
int dp[P][MA+1];
bool activated = false;
int go(int digit, int layer){
if (digit == P) return 1;
if (dp[digit][layer] != -1) return dp[digit][layer];
int ans = 0;
for(int j = layer; j <= MA; ++j) ans += go(digit + 1, j);
return dp[digit][layer] = ans;
}
vector<int> get_state(int 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){
int cur = go(i + 1, j);
if (cur < x) {
x -= cur;
}
else{
layer = j;
break;
}
}
if (layer > 0) ans.push_back(layer-1);
}
return ans;
}
int get_order(vector<int> state){
if (!activated) {
memset(dp, -1, sizeof dp);
activated = true;
}
int 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 decode(int N, int L, int X[]){
vector<int> ans(N + 3);
vector<vector<int>> cur((N + 2) / 3);
for(int i = 0; i < L; ++i){
cur[X[i] / 12].push_back(X[i]);
}
for(int i = 0; i < cur.size(); ++i){
sort(ALL(cur[i]));
for(int &j: cur[i]) j -= i * MA;
int idx = get_order(cur[i]);
ans[i * 3] = idx % MASK(8);
ans[i * 3 + 1] = (idx / MASK(8)) % MASK(8);
ans[i * 3 + 2] = (idx / MASK(16));
}
while(ans.size() > N) ans.pop_back();
for(int i: ans) output(i);
}
컴파일 시 표준 에러 (stderr) 메시지
encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:118:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | 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:130:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
130 | 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... |