# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
712451 | BackNoob | 앵무새 (IOI11_parrots) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "encoder.h"
#include "encoderlib.h"
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int BASE = 1e9;
const int LOG = 20;
struct bigint{
int arr[23];
bigint(){
memset(arr, 0, sizeof(arr));
}
} choose[607][306];
bigint add(bigint a, bigint b)
{
bigint res;
for(int i = 0; i < 21; i++) {
int tmp = a.arr[i] + b.arr[i];
res.arr[i + 1] += tmp / BASE;
res.arr[i] += tmp % BASE;
}
return res;
}
bigint sub(bigint a, bigint b)
{
bigint res;
for(int i = 0; i < 21; i++) {
while(a.arr[i] < b.arr[i]) {
a.arr[i] += BASE;
a.arr[i + 1]--;
}
res.arr[i] = a.arr[i] - b.arr[i];
}
return res;
}
bigint Div(bigint a, int b)
{
bigint res;
ll rem = 0;
for(int i = 20; i >= 0; i--) {
res.arr[i] = (ll) (1LL * BASE * rem + a.arr[i]) / b;
rem = (rem * BASE + a.arr[i]) % b;
}
return res;
}
int Mod(bigint a, int b)
{
ll res = 0;
for(int i = 20; i >= 0; i--) {
res = 1LL * res * BASE + a.arr[i];
res %= b;
}
return res;
}
int cmp(bigint a, bigint b)
{
for(int i = 20; i >= 0; i--) {
if(a.arr[i] == b.arr[i]) continue;
if(a.arr[i] < b.arr[i]) return -1;
return 1;
}
return 0;
}
void encode(int n, int a[])
{
bigint x;
for(int i = 0; i < n; i++) {
bigint tmp; tmp.arr[0] = a[i];
bigint t = x;
for(int j = 1; j < 256; j++) x = add(x, t);
x = add(x, tmp);
}
bigint t;
t.arr[0] = 1;
x = add(x, t);
for(int i = 0; i <= 530; i++) {
choose[i][0].arr[0] = 1;
for(int j = 1; j <= min(256, i); j++) {
choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
}
}
bigint lim;
lim.arr[0] = 1;
for(int i = 1; i <= n * 8; i++) {
lim = add(lim, lim);
}
int k = 1;
while(cmp(choose[256 + k - 1][256], lim) == -1) ++k;
int sta = 0;
for(int i = 1; i <= k; i++) {
for(int j = sta; j <= 255; j++) {
bigint way = choose[255 - j + (k - i)][255 - j];
int tmp = cmp(x, way);
if(tmp <= 0) {
send(j);
sta = j;
break;
}
else {
x = sub(x, way);
}
}
}
}
#include "decoder.h"
#include "decoderlib.h"
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int BASE = 1e9;
const int LOG = 20;
struct bigint{
int arr[23];
bigint(){
memset(arr, 0, sizeof(arr));
}
} choose[607][306];
bigint add(bigint a, bigint b)
{
bigint res;
for(int i = 0; i < 21; i++) {
int tmp = a.arr[i] + b.arr[i];
res.arr[i + 1] += tmp / BASE;
res.arr[i] += tmp % BASE;
}
return res;
}
bigint sub(bigint a, bigint b)
{
bigint res;
for(int i = 0; i < 21; i++) {
while(a.arr[i] < b.arr[i]) {
a.arr[i] += BASE;
a.arr[i + 1]--;
}
res.arr[i] = a.arr[i] - b.arr[i];
}
return res;
}
bigint Div(bigint a, int b)
{
bigint res;
ll rem = 0;
for(int i = 20; i >= 0; i--) {
res.arr[i] = (ll) (1LL * BASE * rem + a.arr[i]) / b;
rem = (rem * BASE + a.arr[i]) % b;
}
return res;
}
int Mod(bigint a, int b)
{
ll res = 0;
for(int i = 20; i >= 0; i--) {
res = 1LL * res * BASE + a.arr[i];
res %= b;
}
return res;
}
int cmp(bigint a, bigint b)
{
for(int i = 20; i >= 0; i--) {
if(a.arr[i] == b.arr[i]) continue;
if(a.arr[i] < b.arr[i]) return -1;
return 1;
}
return 0;
}
void encode(int n, int a[])
{
bigint x;
for(int i = 0; i < n; i++) {
bigint tmp; tmp.arr[0] = a[i];
bigint t = x;
for(int j = 1; j < 256; j++) x = add(x, t);
x = add(x, tmp);
}
bigint t;
t.arr[0] = 1;
x = add(x, t);
for(int i = 0; i <= 530; i++) {
choose[i][0].arr[0] = 1;
for(int j = 1; j <= min(256, i); j++) {
choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
}
}
bigint lim;
lim.arr[0] = 1;
for(int i = 1; i <= n * 8; i++) {
lim = add(lim, lim);
}
int k = 1;
while(cmp(choose[256 + k - 1][256], lim) == -1) ++k;
int sta = 0;
for(int i = 1; i <= k; i++) {
for(int j = sta; j <= 255; j++) {
bigint way = choose[255 - j + (k - i)][255 - j];
int tmp = cmp(x, way);
if(tmp <= 0) {
send(j);
sta = j;
break;
}
else {
x = sub(x, way);
}
}
}
}
void decode(int n, int l, int a[])
{
vector<int> v;
for(int i = 0; i < l; i++) v.pb(a[i]);
sort(all(v));
for(int i = 0; i <= 530; i++) {
choose[i][0].arr[0] = 1;
for(int j = 1; j <= min(256, i); j++) {
choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
}
}
bigint res;
int sta = 0;
for(int i = 1; i <= sz(v); i++) {
int x = v[i - 1];
for(int j = sta; j < x; j++) {
res = add(res, choose[(255 - j) + (sz(v) - i)][(255 - j)]);
}
sta = x;
}
vector<int> ans;
for(int i = 1; i <= n; i++) {
ans.pb(Mod(res, 256));
res = Div(res, 256);
}
reverse(all(ans));
for(auto it : ans) output(it);
}