Cod sursa(job #2767997)

Utilizator nstefanNeagu Stefan nstefan Data 8 august 2021 21:40:30
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <bits/stdc++.h>

#define __NAME_OF_THE_FILE__ "perle"

std::array<int, 10005> perls;
size_t checkB(size_t i);
size_t checkC(size_t i);

/*
  B :=   2B   |
         1A3AC
*/
size_t checkB(size_t i) {
  if (perls[i] == 2) {
    return checkB(i + 1);
  }

  if (perls[i] == 1) {
    if (perls[i + 2] == 3) {
      return checkC(i + 4);
    }
  }

  return 0;
};

/*
  C :=   2   |
         3BC |
         12A
*/
size_t checkC(size_t i) {
  if (perls[i] == 2) {
    return i + 1;
  }

  if (perls[i] == 3) {
    return checkC(checkB(i + 1));
  }

  if (perls[i] == 1) {
    if (perls[i + 1] == 2) {
      return i + 3;
    }
  }

  return 0;
};

int main() {
  freopen(__NAME_OF_THE_FILE__ ".in", "r", stdin);
#ifdef INFOARENA
  freopen(__NAME_OF_THE_FILE__ ".out", "w", stdout);
#endif

  // read the tests
  size_t testCount;
  scanf("%zu", &testCount);
  while (testCount--) {
    // read the perls
    size_t perlsCount;
    scanf("%zu", &perlsCount);
    for (size_t i = 0; i < perlsCount; i++) {
      scanf("%i", &perls[i]);
    }

    // solve the test
    if (perlsCount == 1 || checkB(0) == perlsCount ||
        checkC(0) == perlsCount) {
      printf("1\n");
    } else {
      printf("0\n");
    }

    // reset the perls string
    perls = {};
  }

  return 0;
}