Problem p03170 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef pair<ull, ull> p;
#define mp make_pair
#define append push_back
vector<ull> v;
set<ull> s;
multiset<ull> ms;
ull prime[10000000];
#define f(i, a, b) for (int i = a; i < (b); i++)
#define print cout <<
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

vector<ull> visited(10000000, 0);
vector<ull> adj[100000];

struct node {
  ull data;
  node *left;
  node *right;
};

node *getNode(ull val) {
  node *newNode = new node();
  newNode->data = val;
  newNode->left = newNode->right = NULL;
  return newNode;
}

node *findNode(node *root, ull data) {
  if (root->data == data)
    return root;
  if (root->left)
    findNode(root->left, data);
  if (root->right)
    findNode(root->right, data);
}

void display(node *root) {
  // displaying the tree
  queue<node *> Q;
  Q.push(root);
  while (!Q.empty()) {
    node *x = Q.front();
    Q.pop();
    if (x->left)
      Q.push(x->left);
    if (x->right)
      Q.push(x->right);
    cout << x->data << " ";
  }
  cout << endl;
}

node *copy(node *root) {
  if (!root)
    return root;
  node *temp = new node();
  temp->data = root->data;
  temp->left = copy(root->left);
  temp->right = copy(root->right);
  return temp;
}

void mirror(node *root) {
  if (root) {
    mirror(root->left);
    mirror(root->right);
    node *temp = root->left;
    root->left = root->right;
    root->right = temp;
  }
  return;
}

int findMirror(int target, node *left, node *right) {
  if (left == NULL || right == NULL)
    return 0;
  if (left->data == target)
    return right->data;
  if (right->data == target)
    return left->data;
  int mirrorValue = findMirror(target, left->left, right->right);
  if (mirrorValue)
    return mirrorValue;
  return findMirror(target, left->right, right->left);
}

ull ncrmodp(ull num, ull r, ull mod) {
  ull C[r + 1];
  ull i, j;
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (i = 1; i <= num; i++) {
    for (j = min(i, r); j > 0; j--) {
      C[j] = ((C[j]) % mod + (C[j - 1]) % mod) % mod;
    }
  }
  return C[r];
}

ull multiply(ull n, ull m) {

  ull prod = 1;
  f(i, 0, n) {
    prod *= v[i];
    prod = prod % m;
  }
  return prod;
}

ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); }

ull power(ull x, ull y, ull p) {
  ull res = 1;
  x = x % p;

  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;

    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

void dfs(int k) {
  visited[k] = 1;
  for (int i = 0; i < adj[k].size(); ++i) {
    if (visited[adj[k][i]] == 0) {
      dfs(adj[k][i]);
    }
  }
}

void sieve(ull ending) {
  for (int i = 2; i < ending; i++)
    prime[i] = 1;
  for (int i = 2; i * i <= ending; i++) {
    if (prime[i] == 1) {
      for (int j = 2 * i; j <= ending; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  prime[1] = 0;
}

ull mex(set<ull> s) {
  ull me = 0;
  while (s.find(me) != s.end())
    me++;
  return me;
}

ull k, n;
ull dp[100005] = {0};
void grundy() {
  ull j = v[0], l, i;
  for (i = 0; i < j; i++)
    dp[i] = 0;
  for (i = j; i <= k; i++) {
    set<ull> s;
    for (l = 0; l < n; l++) {
      if (i - v[l] < 0)
        break;
      else
        s.insert(dp[i - v[l]]);
    }
    dp[i] = mex(s);
  }
}

int main() {
  boost();
  ull i, j;
  ull t, m;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    ull a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  grundy();
  if (!dp[k])
    cout << "Second" << endl;
  else
    cout << "First" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ull;
typedef pair<ull, ull> p;
#define mp make_pair
#define append push_back
vector<ull> v;
set<ull> s;
multiset<ull> ms;
ull prime[10000000];
#define f(i, a, b) for (int i = a; i < (b); i++)
#define print cout <<
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

vector<ull> visited(10000000, 0);
vector<ull> adj[100000];

struct node {
  ull data;
  node *left;
  node *right;
};

node *getNode(ull val) {
  node *newNode = new node();
  newNode->data = val;
  newNode->left = newNode->right = NULL;
  return newNode;
}

node *findNode(node *root, ull data) {
  if (root->data == data)
    return root;
  if (root->left)
    findNode(root->left, data);
  if (root->right)
    findNode(root->right, data);
}

void display(node *root) {
  // displaying the tree
  queue<node *> Q;
  Q.push(root);
  while (!Q.empty()) {
    node *x = Q.front();
    Q.pop();
    if (x->left)
      Q.push(x->left);
    if (x->right)
      Q.push(x->right);
    cout << x->data << " ";
  }
  cout << endl;
}

node *copy(node *root) {
  if (!root)
    return root;
  node *temp = new node();
  temp->data = root->data;
  temp->left = copy(root->left);
  temp->right = copy(root->right);
  return temp;
}

void mirror(node *root) {
  if (root) {
    mirror(root->left);
    mirror(root->right);
    node *temp = root->left;
    root->left = root->right;
    root->right = temp;
  }
  return;
}

int findMirror(int target, node *left, node *right) {
  if (left == NULL || right == NULL)
    return 0;
  if (left->data == target)
    return right->data;
  if (right->data == target)
    return left->data;
  int mirrorValue = findMirror(target, left->left, right->right);
  if (mirrorValue)
    return mirrorValue;
  return findMirror(target, left->right, right->left);
}

ull ncrmodp(ull num, ull r, ull mod) {
  ull C[r + 1];
  ull i, j;
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (i = 1; i <= num; i++) {
    for (j = min(i, r); j > 0; j--) {
      C[j] = ((C[j]) % mod + (C[j - 1]) % mod) % mod;
    }
  }
  return C[r];
}

ull multiply(ull n, ull m) {

  ull prod = 1;
  f(i, 0, n) {
    prod *= v[i];
    prod = prod % m;
  }
  return prod;
}

ull gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); }

ull power(ull x, ull y, ull p) {
  ull res = 1;
  x = x % p;

  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;

    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

void dfs(int k) {
  visited[k] = 1;
  for (int i = 0; i < adj[k].size(); ++i) {
    if (visited[adj[k][i]] == 0) {
      dfs(adj[k][i]);
    }
  }
}

void sieve(ull ending) {
  for (int i = 2; i < ending; i++)
    prime[i] = 1;
  for (int i = 2; i * i <= ending; i++) {
    if (prime[i] == 1) {
      for (int j = 2 * i; j <= ending; j = j + i) {
        prime[j] = 0;
      }
    }
  }
  prime[1] = 0;
}

ull mex(set<ull> s) {
  ull me = 0;
  while (s.find(me) != s.end())
    me++;
  return me;
}

ull k, n;
ull dp[100005] = {0};
void grundy() {
  ull j = v[0], l, i;
  for (i = 0; i < j; i++)
    dp[i] = 0;
  for (i = j; i <= k; i++) {
    set<ull> s;
    for (l = 0; l < n; l++) {
      if (i - v[l] < 0)
        break;
      else
        s.insert(dp[i - v[l]]);
    }
    dp[i] = mex(s);
  }
}

int main() {
  boost();
  ull i, j;
  ull t, m;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    ull a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  grundy();
  if (!dp[k])
    cout << "Second" << endl;
  else
    cout << "First" << endl;
  return 0;
}