| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1296411 | chikien2009 | Broken Device (JOI17_broken_device) | C++20 | 0 ms | 0 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;
}
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)
{
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, 0, 0, 1);
}
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 Bruno(int n, int a[])
{
vector<int> v;
long long res = 0;
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))
{
v.push_back(1);
}
else if (a[i] == 0 && a[i + 1] == 1 && a[i + 2] == 0)
{
v.push_back(0);
}
else if (a[i] == 0)
{
v.push_back(0);
v.push_back(1);
}
else
{
v.push_back(a[i + 2]);
v.push_back(a[i + 1]);
}
}
while (!v.empty() && v.back() == 0)
{
v.pop_back();
}
reverse(v.begin(), v.end());
for (auto & i : v)
{
res <<= 1;
res += i;
}
return res;
}
