Submission #1295269

#TimeUsernameProblemLanguageResultExecution timeMemory
1295269NValchanovAncient Machine (JOI21_ancient_machine)C++20
5 / 100
34 ms6360 KiB
#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(n, false);

    stack < llong > st;

    int lampa = -1;

    for(llong i = 0; i < n; i++)
    {
        if(s[i] == 'X')
        {
            if(lampa == -1)
            {
                red[i] = true;
                lampa = i;

                if(i != n - 1)
                {
                    red[i + 1] = false;
                    i++;

                    continue;
                }
            }
            else
            {
                red[i] = false;
            }
        }
        else if(s[i] == 'Y')
        {
            red[i] = false;
        }
        else if(s[i] == 'Z')
        {
            if(lampa == -1)
            {
                red[i] = false;
            }
            else if(i == n - 1)
            {
                red[i] = true;
            }
            else if(s[i + 1] != 'Z')
            {
                red[i] = true;
            }
            else
            {
                red[i] = false;
            }
        }
    }

    assert(red.size() == n);

    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)
                break;

            red.push_back(b);
        }
    }

    assert(red.size() == n);

    stack < llong > st;

    for(llong i = 0; i < n; i++)
    {
        if(red[i])
        {
            if(st.empty())
            {
                st.push(i);
            }
            else
            {
                while(st.size() >= 2)
                {
                    llong p = st.top();
                    st.pop();

                    Remove(p);
                }

                Remove(i);
            }
        }
        else
        {
            if(st.empty())
            {
                Remove(i);
            }
            else
            {
                st.push(i);
            }
        }
    }

    while(!st.empty())
    {
        llong p = st.top();
        st.pop();

        Remove(p);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...