Submission #573544

# Submission time Handle Problem Language Result Execution time Memory
573544 2022-06-06T19:23:58 Z Deepesson Parrots (IOI11_parrots) C++17
99 / 100
8 ms 1356 KB
/**Encoder**/
#include <bits/stdc++.h>
//#include "encoder.h"
//#include "encoderlib.h"
 
void send(int a);
 
std::string enviar;
int qtdzeros,qtduns;
 
void inserezero(void){
    if(!qtdzeros)assert(0);
    --qtdzeros;
    enviar+="0";
}
 
void insereum(void){
    if(!qtduns)assert(0);
    --qtduns;
    enviar+="1";
}
 
std::string plano;
 
void codificar_e_enviar(){
    //std::cout<<enviar<<" envia\n";
    int cur=0;
    int count=0;
    for(auto&x:enviar){
        if(x=='1'){
            ++cur;
        }else {send(cur);++count;}
    }
}
 
void encode(int N, int M[])
{
    qtduns=256;
    qtdzeros=N*9;
    enviar="";
    plano="";
    int count = 0;
    for(int i=0;i!=N;++i){
        for(int j=0;j!=8;++j){
            bool valor = (bool)((M[i]^145)&(1<<j));
            count+=valor;
            plano.push_back(valor+48);
        }
    }
    if(count>256){
        insereum();
    }else inserezero();
    for(int i=0;i!=plano.size();++i){
        bool valor = plano[i]-48;
        if(count>256){
            valor=!valor;
        }
        if(valor)insereum();else inserezero();
    }
    codificar_e_enviar();
}
/**Decoder**/
#include <bits/stdc++.h>
 
//#include "decoder.h"
//#include "decoderlib.h"
void output(int b);
 
void decode(int N, int L, int X[])
{
    int count[256]={};
      for(int i=0; i<L; i++) {
        count[X[i]]++;
      }
    std::string trueseq;
    int cur=0;
    while(cur!=256){
        if(count[cur]){
            --count[cur];
            trueseq.push_back('0');
        }else {
            ++cur;
            trueseq.push_back('1');
        }
    }
  //  std::cout<<"Recebe "<<trueseq<<"\n";
    cur=1;
    bool inverte = trueseq[0]-48;
    for(int i=0;i!=N;++i){
        int ans=0;
        for(int j=0;j!=8;++j){
            int p = (1<<j);
            bool k = trueseq[cur]-48;
            if(inverte)k=!k;
            if(k)ans+=p;
            ++cur;
        }
        output(ans^145);
    }
}

Compilation message

encoder.cpp: In function 'void encode(int, int*)':
encoder.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i!=plano.size();++i){
      |                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1032 KB Output is correct
2 Correct 2 ms 1036 KB Output is correct
3 Correct 2 ms 1036 KB Output is correct
4 Correct 3 ms 1048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1036 KB Output is correct
2 Correct 3 ms 1036 KB Output is correct
3 Correct 3 ms 1036 KB Output is correct
4 Correct 3 ms 1048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1032 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 3 ms 1072 KB Output is correct
4 Correct 4 ms 992 KB Output is correct
5 Correct 3 ms 1036 KB Output is correct
6 Correct 4 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 3 ms 1048 KB Output is partially correct - P = 5.125000
2 Partially correct 3 ms 1064 KB Output is partially correct - P = 5.031250
3 Partially correct 3 ms 1004 KB Output is partially correct - P = 5.030303
4 Partially correct 5 ms 1284 KB Output is partially correct - P = 5.020000
5 Partially correct 8 ms 1356 KB Output is partially correct - P = 5.016667
6 Partially correct 7 ms 1348 KB Output is partially correct - P = 5.015873
7 Partially correct 8 ms 1324 KB Output is partially correct - P = 5.015625