#include "Anna.h"
#include <vector>
#include <stack>
#include <algorithm>
#include <cassert>
#include <iostream>
#define llong long long
using namespace std;
const llong MAXN = 1e5 + 10;
const llong BLOCK_SIZE = 63;
const llong MAXBITS = 44;
namespace {
llong f[BLOCK_SIZE + 2 + 1];
llong encode(vector < bool > v)
{
reverse(v.begin(), v.end());
llong result = 0;
for(llong i = 0; i < BLOCK_SIZE; i++)
{
if(v[i])
result += f[i];
}
return result;
}
void fill_f()
{
f[0] = 1;
f[1] = 2;
for(llong i = 2; i <= BLOCK_SIZE; i++)
{
f[i] = f[i - 1] + f[i - 2];
}
}
}
void Anna(int n, vector<char> s)
{
fill_f();
vector < bool > red;
stack < llong > st;
int lampa = -1;
for(llong i = 0; i < n; i++)
{
if(s[i] == 'X')
{
if(lampa == -1)
{
red.push_back(1);
red.push_back(0);
lampa = i;
}
else
{
red.push_back(0);
}
}
else if(s[i] == 'Y')
{
red.push_back(0);
}
else if(s[i] == 'Z')
{
if(lampa == -1)
{
red.push_back(0);
}
else if(i == n - 1)
{
red.push_back(1);
}
else if(s[i + 1] != 'Z')
{
red.push_back(1);
}
else
{
red.push_back(0);
}
}
}
assert(red.size() == n + 1);
while(red.size() % BLOCK_SIZE != 0)
{
red.push_back(0);
}
llong sz = red.size();
for(llong i = 0; i < sz; i += BLOCK_SIZE)
{
vector < bool > tmp(BLOCK_SIZE);
for(llong j = 0; j < BLOCK_SIZE; j++)
{
tmp[j] = red[i + j];
}
llong type = encode(tmp);
for(llong j = 0; j < MAXBITS; j++)
{
Send(type >> j & 1LL);
}
}
}
#include "Bruno.h"
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <cassert>
#define llong long long
using namespace std;
const llong MAXN = 1e5 + 10;
const llong BLOCK_SIZE = 63;
const llong MAXBITS = 44;
namespace {
llong f[BLOCK_SIZE + 2 + 1];
void fill_f()
{
f[0] = 1;
f[1] = 2;
for(llong i = 2; i <= BLOCK_SIZE; i++)
{
f[i] = f[i - 1] + f[i - 2];
}
}
vector < bool > decode(llong x)
{
vector < bool > result;
for(llong i = BLOCK_SIZE - 1; i >= 0; i--)
{
if(x >= f[i])
{
x -= f[i];
result.push_back(1);
}
else
{
result.push_back(0);
}
}
return result;
}
}
void Bruno(int n, int l, vector < int > a)
{
fill_f();
vector < bool > red;
if(a.size() % MAXBITS != 0)
{
llong ax = 0;
while(1)
{
ax++;
}
}
for(llong i = 0; i < l; i += MAXBITS)
{
llong type = 0;
for(llong j = 0; j < MAXBITS; j++)
{
if(a[i + j])
{
type += (llong)(1LL << j);
}
}
vector < bool > tmp = decode(type);
for(bool b : tmp)
{
if(red.size() == n + 1)
break;
red.push_back(b);
}
}
assert(red.size() == n + 1);
stack < llong > st;
for(llong i = 0; i <= n; i++)
{
if(red[i])
{
if(st.empty())
{
st.push(i);
i++;
}
else
{
while(st.size() >= 2)
{
llong p = st.top();
st.pop();
Remove(p);
}
Remove(i - 1);
}
}
else
{
if(st.empty())
{
Remove(i);
}
else
{
st.push(i - 1);
}
}
}
while(st.size() >= 2)
{
llong p = st.top();
st.pop();
Remove(p);
}
llong x = st.top();
st.pop();
Remove(x);
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |