Submission #1198797

#TimeUsernameProblemLanguageResultExecution timeMemory
1198797mychecksedadAncient Machine (JOI21_ancient_machine)C++20
0 / 100
39 ms6424 KiB
#include "Anna.h"
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 2000+100, M = 1e5+10, K = 52, MX = 30;

namespace {

int variable_example = 0;

}

void Anna(int n, std::vector<char> S) {
  stack<pair<int, char>> st;
  vector<bool> A(n);
  bool phase = false;

  int nice = -1;

  for(int i = 0; i < n; ++i){
    if(st.empty() && S[i] == 'X'){
      st.push({i, S[i]});
      A[i] = 1;
    }else{
      if(st.empty()){
        A[i] = 0;
      }else{
        if(!phase){ // XYXYXYXY
          if(S[i] == 'X'){
            if(st.top().ss == 'Y'){
              A[i] = 1;
              st.push({i, S[i]});
            }else{
              A[i] = 0;
            }
          }else if(S[i] == 'Y'){
            if(st.top().ss == 'X'){
              A[i] = 1;
              st.push({i, S[i]});
            }
          }else{
            if(st.size() == 1){
              A[i] = 0;
              continue;
            }
            if(st.top().ss == 'X'){
              A[st.top().ff] = 0;
              st.pop();
            }
            A[i] = 1;
            phase = true;
            nice = i;
            st.push({i, S[i]});
          }
        }else{
          if(S[i] == 'X'){
            A[i] = 0;
          }else if(S[i] == 'Y'){
            if(st.top().ss == 'Z'){
              A[i] = 1;
              st.push({i, S[i]});
            }else{
              A[i] = 0;
            }
          }else{
            if(st.top().ss == 'Y'){
              A[i] = 1;
              st.push({i, S[i]});
            }else{
              A[i] = 0;
            }
          }
        }
      }
    }
  }
  if(st.size() && st.top().ss != 'Z'){
    A[st.top().ff] = 0;
    st.pop();
  }
  if(nice == -1){
    while(st.size()){
      A[st.top().ff] = 0;
      st.pop();
    }
    nice = 0;
  }
  for(int i = 0; i < n; ++i){
    Send(A[i]);
  }
  bitset<17> b(nice);
  for(int i = 0; i < 17; ++i) Send(b[i]);
}
#include "Bruno.h"
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 2000+100, M = 1e5+10, K = 52, MX = 30;

namespace {

int variable_example = 0;

int FunctionExample(int P) { return 1 - P; }

}  // namespace

void Bruno(int n, int L, std::vector<int> A) {
  int nice = 0;
  vi R;
//   for(int x: A) cerr << x << ' ' ;
// cerr << endl;
  for(int i = 0; i < L - 17; ++i){
    if(A[i] == 0){
      Remove(i);
    }else R.pb(i);
  }
  int idx = L - 17;
  for(int i = 16; i >= 0; --i, idx++) nice += (1<<i)*A[idx];
  if(R.empty()){
    // do nothing
  }else{
    int pos = lower_bound(all(R), nice) - R.begin();
    for(int j = pos - 1; j > 0; --j){
      Remove(R[j]);
    }
    for(int j = pos; j < R.size(); ++j){
      Remove(R[j]);
    }
    Remove(R[0]);
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...