Cod sursa(job #2404308)

Utilizator alexalghisiAlghisi Alessandro Paolo alexalghisi Data 12 aprilie 2019 15:16:36
Problema Perle Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <cstdio>

const int MAX_L = 10000;

int s[5 + MAX_L];
int l;

int c(int pos);

int a(int pos) {
  return pos + 1;
}

int b(int pos) {
  if (s[pos] == 2)
    return b(pos + 1);
  if (s[pos] == 1 && s[pos + 2] == 3)
    return c(pos + 4);
  return l + 5;
}

int c(int pos) {
  if (s[pos] == 2)
    return pos + 1;
  if (s[pos] == 3)
    return c(b(pos + 1));
  if (s[pos] == 1 && s[pos + 1] == 2)
    return a(pos + 2);
  return l + 5;
}

int main() {
  freopen("perle.in", "r", stdin);
  freopen("perle.out", "w", stdout);

  int t;
  scanf("%d", &t);
  for (int test = 0; test < t; test++) {
    scanf("%d", &l);
    for (int i = 1; i <= l; i++)
      scanf("%d", &s[i]);
    if (a(1) == l + 1 || b(1) == l + 1 || c(1) == l + 1)
      printf("1\n");
    else
      printf("0\n");
    for (int i = 1; i <= l; i++)
      s[i] = 0;
  }
  return 0;
}