Problem p03491 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set                                                            \
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector<int> vi;
typedef vector<ll> lvi;
typedef vector<vi> vvi;
typedef vector<lvi> lvvi;
typedef pair<int, int> ii;
typedef pair<ll, ll> lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i)                                                               \
  for (auto i = (c).begin(); i != (c).end(); i++) // remember i is an iterator
#define present(c, x) ((c).find(x) != (c).end())  // for sets,maps,multimaps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define tc(t)                                                                  \
  int(t);                                                                      \
  cin >> (t);                                                                  \
  while ((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
ll n, l, ans = 0;
struct node {
  node *child[2];
  bool isend;
  int depth;
};
node *getnode(int d) {
  node *temp = new node;
  temp->depth = d;
  temp->isend = false;
  temp->child[0] = NULL;
  temp->child[1] = NULL;
  return temp;
}
void insert(string s, int idx, node *curr) {
  if (idx == (int)s.length()) {
    curr->isend = true;
    return;
  }
  if (!curr->child[0])
    curr->child[0] = getnode(curr->depth + 1);
  if (!curr->child[1])
    curr->child[1] = getnode(curr->depth + 1);
  int ch = s[idx] - '0';
  insert(s, idx + 1, curr->child[ch]);
}
void dfs(node *curr) {
  int h = l - curr->depth + 1;
  if (!curr->child[0] && !curr->child[1]) {
    if (curr->isend)
      return;
    ll div = 1;
    for (ll i = 1; i < (1e18 + 5); i <<= 1) {
      if ((h % i) == 0)
        div = i;
    }
    ans ^= div;
    return;
  }
  dfs(curr->child[0]);
  dfs(curr->child[1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> l;
  node *root = getnode(0);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    insert(s, 0, root);
  }
  dfs(root);
  if (ans)
    cout << "Alice\n";
  else
    cout << "Bob\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set                                                            \
  tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector<int> vi;
typedef vector<ll> lvi;
typedef vector<vi> vvi;
typedef vector<lvi> lvvi;
typedef pair<int, int> ii;
typedef pair<ll, ll> lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i)                                                               \
  for (auto i = (c).begin(); i != (c).end(); i++) // remember i is an iterator
#define present(c, x) ((c).find(x) != (c).end())  // for sets,maps,multimaps
#define cpresent(c, x) (find(all(c), x) != (c).end()) // for vectors
#define tc(t)                                                                  \
  int(t);                                                                      \
  cin >> (t);                                                                  \
  while ((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
ll n, l, ans = 0;
struct node {
  node *child[2];
  bool isend;
  int depth;
};
node *getnode(int d) {
  node *temp = new node;
  temp->depth = d;
  temp->isend = false;
  temp->child[0] = NULL;
  temp->child[1] = NULL;
  return temp;
}
void insert(string &s, int idx, node *curr) {
  if (idx == (int)s.length()) {
    curr->isend = true;
    return;
  }
  if (!curr->child[0])
    curr->child[0] = getnode(curr->depth + 1);
  if (!curr->child[1])
    curr->child[1] = getnode(curr->depth + 1);
  int ch = s[idx] - '0';
  insert(s, idx + 1, curr->child[ch]);
}
void dfs(node *curr) {
  int h = l - curr->depth + 1;
  if (!curr->child[0] && !curr->child[1]) {
    if (curr->isend)
      return;
    ll div = 1;
    for (ll i = 1; i < (1e18 + 5); i <<= 1) {
      if ((h % i) == 0)
        div = i;
    }
    ans ^= div;
    return;
  }
  dfs(curr->child[0]);
  dfs(curr->child[1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> l;
  node *root = getnode(0);
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    insert(s, 0, root);
  }
  dfs(root);
  if (ans)
    cout << "Alice\n";
  else
    cout << "Bob\n";
  return 0;
}