Submission #1344120

#TimeUsernameProblemLanguageResultExecution timeMemory
1344120avighnaAncient Machine (JOI21_ancient_machine)C++20
0 / 100
75 ms8736 KiB
#include "Anna.h"
#include <vector>

void Anna(int N, std::vector<char> S) {
  for (int i = 0; i < N; ++i) {
    int x = S[i] - 'X';
    for (int bt = 1; bt >= 0; --bt) {
      Send(!!(x & 1 << bt));
    }
  }
}
#include "Bruno.h"
#include <iostream>
#include <set>
#include <vector>

using namespace std;

void Bruno(int N, int L, std::vector<int> A) {
  vector<char> a(N);
  for (int i = 0; i < N; ++i) {
    a[i] = (A[2 * i] << 1) + A[2 * i + 1] + 'X';
  }

  // everything to the left of the first X is fucked
  // same for the right of the last Z

  int xloc = -1;
  for (int i = N - 1; i >= 0; --i) {
    if (a[i] == 'X') {
      xloc = i;
    }
  }
  int zloc = -1;
  for (int i = 0; i < N; ++i) {
    if (a[i] == 'Z') {
      zloc = i;
    }
  }
  if (xloc == -1 || zloc == -1 || xloc > zloc) { // no X or no Z or first X occurs after last Z
    for (int i = 0; i < N; ++i) {
      Remove(i);
    }
    return;
  }
  for (int i = 0; i < xloc; ++i) {
    Remove(i);
  }
  for (int i = zloc + 1; i < N; ++i) {
    Remove(i);
  }
  int l = xloc == -1 ? 0 : xloc, r = zloc == -1 ? N - 1 : zloc;
  // only a[l...r] remains with a[l] = X and a[r] = Z
  set<int> st;
  vector<int> ys;
  for (int i = l; i <= r; ++i) {
    st.insert(i);
    if (a[i] == 'Y') {
      ys.push_back(i);
    }
  }

  auto erase = [&](int i) {
    st.erase(i);
    Remove(i);
  };
  for (int &i : ys) {
    if (!st.contains(i)) {
      continue;
    }
    auto prev = [&](int i) {
      auto it = st.find(i);
      if (it == st.begin()) {
        return st.end();
      }
      return --it;
    };
    auto next = [&](int i) { return ++st.find(i); };
    for (auto it = prev(i); it != st.end(); it = prev(i)) {
      if (a[*it] == 'X') {
        break;
      }
      erase(*it);
    }
    for (auto it = next(i); it != st.end(); it = next(i)) {
      if (a[*it] == 'Z') {
        break;
      }
      erase(*it);
    }
    erase(i);
  }
  for (auto &i : st) {
    Remove(i);
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...