제출 #1296423

#제출 시각아이디문제언어결과실행 시간메모리
1296423chikien2009Broken Device (JOI17_broken_device)C++20
0 / 100
18 ms1528 KiB
#include "Annalib.h"
void SetBlock(int *pos, int a, int b, int c)
{
    (*pos) = a;
    (*(pos + 1)) = b;
    (*(pos + 2)) = c;
}

void Anna(int n, long long x, int k, int p[])
{
    int dead[n], bit[n];
    for (int i = 0, j = 0; i < n; ++i)
    {
        bit[i] = 0;
        if (j < k && i == p[j])
        {
            dead[i] = 1;
            j++;
        }
        else
        {
            dead[i] = 0;
        }
    }
    for (int i = 0; i < n; i += 3)
    {
        if (dead[i] + dead[i + 1] + dead[i + 2] > 1)
        {
            continue;
        }
        else if (dead[i] + dead[i + 1] + dead[i + 2] == 0)
        {
            if (x % 4 == 0)
            {
                SetBlock(bit + i, 1, 0, 0);
            }
            if (x % 4 == 1)
            {
                SetBlock(bit + i, 1, 0, 1);
            }
            if (x % 4 == 2)
            {
                SetBlock(bit + i, 0, 1, 1);
            }
            if (x % 4 == 3)
            {
                SetBlock(bit + i, 1, 1, 1);
            }
            x >>= 2;
        }
        else if (dead[i] == 1)
        {
            if (x % 2 == 1)
            {
                SetBlock(bit + i, 0, 0, 1);
            }
            if (x % 2 == 0)
            {
                SetBlock(bit + i, 0, 1, 0);
            }
            x >>= 1;
        }
        else if (dead[i + 1] == 1)
        {
            if (x % 4 == 0)
            {
                SetBlock(bit + i, 1, 0, 0);
                x >>= 2;
                continue;
            }
            if (x % 4 == 1)
            {
                SetBlock(bit + i, 1, 0, 1);
                x >>= 2;
                continue;
            }
            if (x % 2 == 1)
            {
                SetBlock(bit + i, 0, 0, 1);
            }
            x >>= 1;
        }
        else
        {
            if (x % 2 == 1)
            {
                SetBlock(bit + i, 1, 1, 0);
            }
            if (x % 2 == 0)
            {
                SetBlock(bit + i, 0, 1, 0);
            }
            x >>= 1;
        }
    }
    for (int i = 0; i < n; ++i)
    {
        Set(i, bit[i]);
    }
}
#include "Brunolib.h"
long long Val(int &len, long long & p, int bit)
{
    if (len < 61)
    {
        len++;
        p <<= 1;
        return bit * p / 2LL;
    }
    return 0;
}

long long Bruno(int n, int a[])
{
    int len = 0;
    long long res = 0, p = 1;
    for (int i = 0; i < n; i += 3)
    {
        if (a[i] == 0 && a[i + 1] == 0 && a[i + 2] == 0)
        {
            continue;
        }
        if ((a[i] == 0 && a[i + 1] == 0 && a[i + 2] == 1) || 
        (a[i] == 1 && a[i + 1] == 1 && a[i + 2] == 0))
        {
            res += Val(len, p, 1);
        }
        else if (a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 0)
        {
            res += Val(len, p, 0);
        }
        else if (a[i] == 0)
        {
            res += Val(len, p, 0);
            res += Val(len, p, 1);
        }
        else
        {
            res += Val(len, p, a[i + 2]);
            res += Val(len, p, a[i + 1]);
        }
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...