제출 #1296431

#제출 시각아이디문제언어결과실행 시간메모리
1296431chikien2009Broken Device (JOI17_broken_device)C++20
100 / 100
20 ms1564 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 % 4LL == 0LL)
            {
                SetBlock(bit + i, 1, 0, 0);
            }
            if (x % 4LL == 2LL)
            {
                SetBlock(bit + i, 1, 0, 1);
            }
            if (x % 4LL == 1LL)
            {
                SetBlock(bit + i, 0, 1, 1);
            }
            if (x % 4LL == 3LL)
            {
                SetBlock(bit + i, 1, 1, 1);
            }
            x >>= 2;
        }
        else if (dead[i] == 1)
        {
            if (x & 1LL)
            {
                SetBlock(bit + i, 0, 0, 1);
            }
            else
            {
                SetBlock(bit + i, 0, 1, 0);
            }
            x >>= 1;
        }
        else if (dead[i + 1] == 1)
        {
            if (x % 4LL == 0LL)
            {
                SetBlock(bit + i, 1, 0, 0);
                x >>= 2;
                continue;
            }
            if (x % 4LL == 2LL)
            {
                SetBlock(bit + i, 1, 0, 1);
                x >>= 2;
                continue;
            }
            if (x & 1LL)
            {
                SetBlock(bit + i, 0, 0, 1);
            }
            x >>= 1;
        }
        else
        {
            if (x & 1LL)
            {
                SetBlock(bit + i, 1, 1, 0);
            }
            else
            {
                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 < 62)
    {
        len++;
        p <<= 1LL;
        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, 1);
            res += Val(len, p, 0);
        }
        else
        {
            res += Val(len, p, a[i + 1]);
            res += Val(len, p, a[i + 2]);
        }
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...