Submission #256270

#TimeUsernameProblemLanguageResultExecution timeMemory
256270SamAnd앵무새 (IOI11_parrots)C++17
96 / 100
11 ms1792 KiB
#include "encoder.h"
#include "encoderlib.h"

void encode(int N, int M[])
{
    int n = N;

    if (n <= 32)
    {
        int z = 0;
        for (int i = 0; i < n; ++i)
        {
            int x = M[i];
            for (int j = 0; j < 8; ++j)
            {
                if ((x & (1 << j)))
                    send(z);
                z++;
            }
        }
    }
    else
    {
        int q1 = 0;
        int z = 0;
        for (int i = 0; i < n; ++i)
        {
            int x = M[i];
            for (int j = 0; j < 4; ++j)
            {
                if ((x & (1 << j)))
                    ++q1;
                if ((x & (1 << (j + 4))))
                {
                    ++q1;
                    ++q1;
                }
                z++;
            }
        }

        int q2 = 4;
        z = 0;
        for (int i = 0; i < n; ++i)
        {
            int x = M[i];
            for (int j = 0; j < 4; ++j)
            {
                if (!(x & (1 << j)))
                    ++q2;
                if (!(x & (1 << (j + 4))))
                {
                    ++q2;
                    ++q2;
                }
                z++;
            }
        }

        if (q1 < q2)
        {
            z = 0;
            for (int i = 0; i < n; ++i)
            {
                int x = M[i];
                for (int j = 0; j < 4; ++j)
                {
                    if ((x & (1 << j)))
                        send(z);
                    if ((x & (1 << (j + 4))))
                    {
                        send(z);
                        send(z);
                    }
                    z++;
                }
            }
        }
        else
        {
            send(0);
            send(0);
            send(0);
            send(0);
            z = 0;
            for (int i = 0; i < n; ++i)
            {
                int x = M[i];
                for (int j = 0; j < 4; ++j)
                {
                    if (!(x & (1 << j)))
                        send(z);
                    if (!(x & (1 << (j + 4))))
                    {
                        send(z);
                        send(z);
                    }
                    z++;
                }
            }
        }
    }
}
#include "decoder.h"
#include "decoderlib.h"

void decode(int N, int L, int X[])
{
    int c[1003] = {};
    int n = N;
    for (int i = 0; i < L; ++i)
        ++c[X[i]];

    if (n <= 32)
    {
        int z = 0;
        for (int i = 0; i < n; ++i)
        {
            int x = 0;
            for (int j = 0; j < 8; ++j)
            {
                if (c[z])
                    x |= (1 << j);
                z++;
            }
            output(x);
        }
    }
    else
    {
        if (!(c[0] & 4))
        {
            int z = 0;
            for (int i = 0; i < n; ++i)
            {
                int x = 0;
                for (int j = 0; j < 4; ++j)
                {
                    if ((c[z] & 1))
                        x |= (1 << j);
                    if ((c[z] & 2))
                        x |= (1 << (j + 4));
                    z++;
                }
                output(x);
            }
        }
        else
        {
            int z = 0;
            for (int i = 0; i < n; ++i)
            {
                int x = 0;
                for (int j = 0; j < 4; ++j)
                {
                    if (!(c[z] & 1))
                        x |= (1 << j);
                    if (!(c[z] & 2))
                        x |= (1 << (j + 4));
                    z++;
                }
                output(x);
            }
        }
    }
}
#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...