이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
const int MAXN = 16;
ll fact[MAXN + 1];
void calc_fact()
{
fact[0] = 1;
for(ll i = 1 ; i <= 16 ; i++)
{
fact[i] = fact[i - 1] * i;
}
}
ll find_code(int n , vector<int> perm)
{
calc_fact();
ll code = 0;
for(int i = 0 ; i <n ;i++)
{
int smaller = 0;
for(int j = i + 1; j < n ;j++)
{
smaller+=(perm[j] < perm[i]);
}
code+=fact[n - i - 1] * smaller;
}
return code;
}
void encode(int N, int M[])
{
map<int , int> compress;
vector<int> cur;
for(int i = 0 ;i < N ; i++)
{
cur.push_back(M[i]);
send(M[i]);
send(M[i]);
}
sort(cur.begin() , cur.end());
for(int i = 0 ; i < N ; i++)
{
compress[cur[i]] = i;
}
vector<int> perm(N);
for(int i = 0 ; i < N ; i++)
{
perm[i] = compress[M[i]];
}
ll code = find_code(N , perm);
int cnt = 1;
while(code)
{
int r = code%10;
send(cnt * 10 + r);
cnt++;
code/=10;
}
}
#include "decoder.h"
#include "decoderlib.h"
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
const int MAXN = 16;
ll fact[MAXN + 1];
void calc_fact()
{
fact[0] = 1;
for(ll i = 1 ; i <= 16 ; i++)
{
fact[i] = fact[i - 1] * i;
}
}
vector<int> find_perm(int n , ll code)
{
calc_fact();
vector<int> nums;
for(int i = 0 ; i < n ; i++)
{
nums.push_back(i);
}
vector<int> perm;
for(int i = 1 ; i <= n; i++)
{
ll idx = code / fact[n - i];
perm.push_back(nums[idx]);
nums.erase(nums.begin() + idx);
code-=idx * fact[n - i];
}
return perm;
}
void decode(int N, int L, int X[])
{
vector<int> vals;
map<int ,int> occ;
for(int i = 0 ; i < L ; i++)
{
occ[X[i]]++;
}
for(int i = 0 ; i < L ; i++)
{
if(occ[X[i]] >= 2)
{
vals.push_back(X[i]);
occ[X[i]]-=2;
}
}
sort(vals.begin(), vals.end());
ll code = 0;
for(auto p : occ)
{
if(p.second == 1)
{
int x = p.first;
ll d = x%10;
x/=10;
code+=d * (ll)pow(10 , x - 1);
}
}
vector<int> perm = find_perm(N , code);
for(auto &x : perm)
{
output(vals[x]);
}
}
# | 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... |