Problem p03491 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for (LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for (LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for (LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c, x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL << (i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n) { return m / gcd(m, n) * n; }

template <typename I> void join(ostream &ost, I s, I t, string d = " ") {
  for (auto i = s; i != t; ++i) {
    if (i != s)
      ost << d;
    ost << *i;
  }
  ost << endl;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &a : v)
    is >> a;
  return is;
}

template <typename T, typename U> bool chmin(T &a, const U &b) {
  return (a > b ? a = b, true : false);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
  return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <int N> class Trie {
public:
  int table[N];

  struct node {
    int val;
    node *ch[N] = {};

    node(int val) : val(val) {}
    node() : val(0) {}
  };

  Trie(const string &s) {
    REP(i, (int)s.size()) { table[(int)s[i]] = i; }
  }

  node *root = nullptr;

  node *insert(node *t, const string &s, int val, int i) {
    if (!t)
      t = new node();

    if (i >= (int)s.size()) {
      t->val = val;
      return t;
    }

    int c = table[(int)s[i]];
    t->ch[c] = insert(t->ch[c], s, val, i + 1);

    return t;
  }

  void insert(const string &s, int val) { root = insert(root, s, val, 0); }

  node *find(node *t, char c) {
    if (!t)
      return t;
    return t->ch[table[(int)c]];
  }

  node *find(const string &s) {
    node *t = root;
    int i = 0;

    while (t and i < (int)s.size()) {
      t = find(t, s[i]);
      if (!t)
        return nullptr;
      ++i;
    }

    return t;
  }
};

LLI dfs(Trie<2>::node *t, int d) {
  LLI ret = 0;

  if (!t->val) {
    REP(i, 2) {
      if (t->ch[i]) {
        ret ^= dfs(t->ch[i], d - 1);
      } else {
        LLI x = 1;

        while (d % (x * 2) == 0) {
          x *= 2;
        }

        ret ^= x;
      }
    }
  }

  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  LLI N, L;
  while (cin >> N >> L) {
    Trie<2> trie("01");

    REP(i, N) {
      string s;
      cin >> s;
      trie.insert(s, 1);
    }

    LLI ans = dfs(trie.root, L);

    cout << (ans ? "Alice" : "Bob") << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for (LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for (LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for (LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for (auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for (auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c, x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL << (i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n) { return m / gcd(m, n) * n; }

template <typename I> void join(ostream &ost, I s, I t, string d = " ") {
  for (auto i = s; i != t; ++i) {
    if (i != s)
      ost << d;
    ost << *i;
  }
  ost << endl;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &a : v)
    is >> a;
  return is;
}

template <typename T, typename U> bool chmin(T &a, const U &b) {
  return (a > b ? a = b, true : false);
}
template <typename T, typename U> bool chmax(T &a, const U &b) {
  return (a < b ? a = b, true : false);
}
template <typename T, size_t N, typename U>
void fill_array(T (&a)[N], const U &v) {
  fill((U *)a, (U *)(a + N), v);
}

template <int N> class Trie {
public:
  int table[N];

  struct node {
    int val;
    node *ch[N] = {};

    node(int val) : val(val) {}
    node() : val(0) {}
  };

  Trie(const string &s) {
    REP(i, (int)s.size()) { table[(int)s[i]] = i; }
  }

  node *root = nullptr;

  node *insert(node *t, const string &s, int val, int i) {
    if (!t)
      t = new node();

    if (i >= (int)s.size()) {
      t->val = val;
      return t;
    }

    int c = table[(int)s[i]];
    t->ch[c] = insert(t->ch[c], s, val, i + 1);

    return t;
  }

  void insert(const string &s, int val) { root = insert(root, s, val, 0); }

  node *find(node *t, char c) {
    if (!t)
      return t;
    return t->ch[table[(int)c]];
  }

  node *find(const string &s) {
    node *t = root;
    int i = 0;

    while (t and i < (int)s.size()) {
      t = find(t, s[i]);
      if (!t)
        return nullptr;
      ++i;
    }

    return t;
  }
};

LLI dfs(Trie<2>::node *t, LLI d) {
  LLI ret = 0;

  if (!t->val) {
    REP(i, 2) {
      if (t->ch[i]) {
        ret ^= dfs(t->ch[i], d - 1);
      } else {
        LLI x = 1;

        while (d % (x * 2) == 0) {
          x *= 2;
        }

        ret ^= x;
      }
    }
  }

  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  LLI N, L;
  while (cin >> N >> L) {
    Trie<2> trie("01");

    REP(i, N) {
      string s;
      cin >> s;
      trie.insert(s, 1);
    }

    LLI ans = dfs(trie.root, L);

    cout << (ans ? "Alice" : "Bob") << endl;
  }

  return 0;
}