# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38321 | pce913 | Parrots (IOI11_parrots) | C++14 | 0 ms | 0 KiB |
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 "encoder.h"
#include "encoderlib.h"
#include<vector>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int org[256][4];
void encode(int N, int M[])
{
memset(org, 0, sizeof(org));
for (int x = 0; x < N ; x++){
int num = M[x];
bool find = false;
for (int i = 0; i < 256; i++){ // 1
for (int j = 0; j < 64; j++){ //4
for (int k = 0; k < 16; k++){ //16
for (int l = 0; l < 4; l++){ //64
if (i + 4 * j + 16 * k + 64 * l == num){
org[num][0] = i, org[num][1] = j;
org[num][2] = k, org[num][3] = l;
find = true;
break;
}
}
if (find)break;
}
if (find)break;
}
if (find)break;
}
}
vector<int> a;
for (int x = 0; x < N; x++){
int num = M[x];
int in = x << 3;
int n1 = org[num][0], n4 = org[num][1];
int n16 = org[num][2], n64 = org[num][3];
int min1_4 = min(n1, n4), max1_4 = max(n1, n4);
int min16_64 = min(n16, n64), max16_64 = max(n16, n64);
for (int i = 0; i < min1_4; i++)
a.push_back(in + (1 << 1) + 1);
for (int i = 0; i < max1_4 - min1_4; i++){
if (max1_4 == n1)
a.push_back(in + (1 << 1));
else
a.push_back(in + 1);
}
for (int i = 0; i < min16_64; i++)
a.push_back(in + (1 << 2) + (1 << 1) + 1);
for (int i = 0; i < max16_64 - min16_64; i++){
if (max16_64 == n16)
a.push_back(in + (1 << 2) + (1 << 1));
else
a.push_back(in + (1 << 2) + 1);
}
}
for (int i = 0; i < a.size(); i++) //인코딩 시킨 숫자
send(a[i]);
}
#include "decoder.h"
#include "decoderlib.h"
#include<cstring>
#include<iostream>
using namespace std;
int ans[260];
void decode(int N, int L, int X[]) //N:원래 메시지의 길이, L:전송된 메시지의 길이
{
memset(ans, 0, sizeof(ans));
for (int i = 0; i < L; i++){
int ord = X[i] >> 3;
int num = X[i] & 7;
if (num&(1 << 2)){
if (num&(1 << 1))
ans[ord] += 16;
if (num&(1 << 0)){
ans[ord] += 64;
}
else{
if (num&(1 << 1))
ans[ord] += 1;
if (num&(1 << 0))
ans[ord] += 4;
}
}
for (int i = 0; i < N; i++)
output(ans[i]);
}