# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094096 | Aviansh | Parrots (IOI11_parrots) | C++17 | 12 ms | 1416 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 <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"
using namespace std;
void encode(int n, int m[])
{
int buf = ceil(log2(n));
int bufn = 3;
string s="";
for(int i = 0;i<n;i++){
for(int j = 7;j>=0;j--){
if(1<<j&m[i]){
s+='1';
}
else{
s+='0';
}
}
}
//cout << "string generated: " << s << "\n";
int ind = 0;
int curnum = bufn-1;
for(int i = 0;i<(1<<buf)&&ind<s.size();i++){
int cur = i<<(8-buf);
int par = 0;
for(int i = 0;i<8-buf;i++){
//cout << "adding point at index: " << ind+i << "\n";
if(ind+i>=s.size()) continue;
if(s[(ind+i)]=='1'){
par+=(1<<(8-buf-1-i));
}
}
//cout << "\n";
ind+=8-buf;
cur+=par;
for(int i = 0;i<(1<<curnum);i++){
//cout << "sending number: " << cur << "\n";
string c = "";
for(int i = 0;i<8;i++){
if(1<<i&cur){
c="1"+c;
}
else{
c="0"+c;
}
}
//cout << c << "\n";
send(cur);
}
curnum--;
if(curnum==-1){
curnum=bufn-1;
i++;
}
i--;
}
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"
using namespace std;
void decode(int n, int l, int x[])
{
int buf = ceil(log2(n));
int bufn = 3;
sort(x,x+l);
string s = "";
map<int,int>mp[1<<buf];
for(int i = 0;i<l;i++){
//cout << "recieved: " << (x[i]>>(7-buf))<< " " << x[i]%(1<<(7-buf)) << "\n";
mp[x[i]>>(8-buf)][x[i]%(1<<(8-buf))]++;
}
for(int i = 0;i<(1<<(buf));i++){
//cout << "at: " << i << "\n";
for(int lim = bufn-1;lim>=0;lim--){
int mn = 1<<lim;
for(pair<int,int>p:mp[i]){
if(p.second>=mn){
string c = "";
for(int i = 0;i<8-buf;i++){
if(1<<i&p.first){
c="1"+c;
}
else{
c="0"+c;
}
}
s+=c;
mp[i][p.first]-=mn;
break;
}
}
}
//cout << s << "\n";
}
//cout << "string found: " << s << "\n";
string curr = "";
int cn = 0;
for(int i = 0;i<s.size();i++){
curr+=s[i];
if(i%8==7){
//cout << "geting num: " << curr << "\n";
int num = 0;
for(int i = 0;i<8;i++){
if(curr[i]=='1'){
num+=1<<(7-i);
}
}
//cout << "outputting: " << num << "\n";
output(num);
cn++;
if(cn==n){
return;
}
curr="";
}
}
}
Compilation message (stderr)
# | 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... |