Submission #770159

#TimeUsernameProblemLanguageResultExecution timeMemory
770159teamariaaParrots (IOI11_parrots)C++17
17 / 100
2 ms1104 KiB
#include <bits/stdc++.h>
#include "encoder.h"
#include "encoderlib.h"

using namespace std;

/// ratio 6N +  8(flaguri)
void encode(int n, int m[])
{
    bitset <256> code;

    if(n == 1)
    {
        send(m[0]);
        return;
    }

    for(int i = 0; i < 8 * n; i ++)
        code[i] = 0;
    int j;
    for(int i = 0; i < n; i ++)
    {
        j = 0;
        int copie = m[i];
        while(copie)
        {
            code[8 * (i + 1) - 1 - j] = copie % 2;
            copie >>= 1;
            j ++;
        }
    }

    int cnt1 = 0, cnt0 = 0, flag = 0;
    for(int i = 0; i < 4 * n; i ++)
    {
        if(code[i] == 1)
            cnt1 ++;
        else
            cnt0 ++;
    }

    if(cnt1 <= cnt0)
    {
        flag = 1;
        send(1);
        send(1);
        send(1);
        send(1);
    }

    for(int i = 0; i < 4 * n; i ++)
    {
        if(code[i] == flag)
            send(i);
    }

///////////////////////////////////

    cnt1 = 0, cnt0 = 0;

    for(int i = 4 * n; i < 8 * n; i ++)
    {
        if(code[i] == 1)
            cnt1 ++;
        else
            cnt0 ++;
    }

    if(cnt1 <= cnt0)
    {
        flag = 1;
        send(0);
        send(0);
        send(0);
        send(0);
    }

    for(int i = 4 * n; i < 8 * n; i ++)
    {
        if(code[i] == flag)
        {
            send(i - 4 * n);
            send(i - 4 * n);
        }
    }
}
#include <bits/stdc++.h>
#include "decoder.h"
#include "decoderlib.h"

using namespace std;

void decode(int n, int l, int x[])
{
    if(l == 1)
    {
        output(x[0]);
        return;
    }

    bitset <256> code;

    for(int i = 0; i < 8 * n; i ++)
        code[i] = 0;

    sort(x, x + l);

    int cnt, flag1 = 0, flag2 = 0, i;

    cnt = 1, i = 0;

    if(x[i] == 0)
    {
        while(i < l  &&  x[i] == x[i + 1])
        {
            i ++;
            cnt ++;
        }

        if(cnt >= 4)
            flag2 = 1;
        i ++;
    }

    if(x[i] == 1)
    {
        while(i < l  &&  x[i] == x[i + 1])
        {
            i ++;
            cnt ++;
        }

        if(cnt >= 4)
            flag1 = 1;
        i ++;
    }

    for(int i = 0; i < 4 * n; i ++)
        code[i] = 1 - flag1;
    for(int i = 4 * n; i < 8 * n; i ++)
        code[i] = 1 - flag2;

    i = 0;
    for(int i = 0; i < l; i ++)
    {
        cnt = 1;
        while(i < l - 1  &&  x[i] == x[i + 1])
        {
            i ++;
            cnt ++;
        }

        if((x[i] == 0  ||  x[i] == 1)  &&  cnt >= 4)
            cnt -=4;

        if(cnt == 1  ||  cnt == 3)
            code[x[i]] = flag1;
        if(cnt == 2  ||  cnt == 3)
            code[4 * n + x[i]] = flag2;
    }

    for(int i = 7; i < 8 * n; i +=8)
    {
        int pow = 1, nr = 0;
        for(int j = 0; j <= 7; j ++, pow <<= 1)
            nr += code[i - j] * pow;
        output(nr);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...