Submission #548384

#TimeUsernameProblemLanguageResultExecution timeMemory
548384TrungNotChungAncient Machine (JOI21_ancient_machine)C++17
38 / 100
87 ms9176 KiB
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x)  (1LL<<(x))
#define CNT(x) __builtin_popcountll(x)
#include <bits/stdc++.h>
#include "Anna.h"
 
const char ch[] = {'X' , 'Y' , 'Z'};
long long pw[50];
void Anna(int N, std::vector<char> S) {
  pw[0] = 1;
  for(int i=1 ; i<=38 ; ++i) pw[i] = 1LL * pw[i-1] * 3;
  for(int i=0 ; i<N ; i+=38)
  {
    long long tmp = 0;
    for(int j=i ; j<=std::min(N-1 , i+37) ; ++j)
    {
      for(int k=0 ; k<3 ; ++k) if(S[j] == ch[k])
      {
        tmp += pw[j-i] * k;
      }
    }
    for(int j=0 ; j<=62 ; ++j) Send(BIT(tmp , j));
  }
}
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x)  (1LL<<(x))
#define CNT(x) __builtin_popcountll(x)
#include <bits/stdc++.h>
#include "Bruno.h"
 
const char ch[] = {'X' , 'Y' , 'Z'};
long long pw[50];
void Bruno(int N, int L, std::vector<int> A)
{ 
  std::vector<char> s;
  for(int i=0 ; i<L ; i+=63)
  {
    long long tmp = 0;
    for(int j=0 ; j<=62 ; ++j)
    {
      if(A[i+j] == 1) tmp += MASK(j);
    }
    for(int j=1 ; j<=38 ; ++j)
    {
      int c = tmp % 3;
      tmp /= 3;
      s.push_back(ch[c]);
      if((int)s.size() == N) break;
    }
  }
  std::stack<int> st;
  for(int i=0 ; i<N ; ++i)
  {
    if(st.size() && s[i] == s[st.top()])
    {
      Remove(i);
      continue;
    }
    if(s[i] == 'X')
    {
      st.push(i);
    }
    else if(s[i] == 'Y')
    {
      if(st.size()) st.push(i);
      else Remove(i);
    }
    else 
    {
      if((int)st.size() < 2)
      {
        Remove(i);
        continue;
      }
      if(st.size() && s[st.top()] == 'X') 
      {
        Remove(st.top());
        st.pop();
      }
      while((int)st.size() > 2)
      {
        Remove(st.top());
        st.pop();
        Remove(st.top());
        st.pop();
      }
      if((int)st.size() == 2)
      {
        Remove(st.top());
        st.pop();
      }
      Remove(i);
    }
  }
  while(st.size()) Remove(st.top()) , st.pop();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...