Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
  cout.flush();
  cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class T> ostream &operator<<(ostream &out, vector<T> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}
template <class T> ostream &operator<<(ostream &out, set<T> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}
template <class L, class R> ostream &operator<<(ostream &out, map<L, R> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}

const ll MAXN = 12;
const ll MASK = (1 << MAXN);
const ll INF = 1e12;

void upd(ll &x, ll y) { x = min(x, y); }

int main() {
  cout << fixed << setprecision(30);
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  ll n, m;
  cin >> n >> m;
  vl costs(m);
  vl masks(m);

  for (ll i = 0; i < m; ++i) {
    ll cnt;
    cin >> costs[i] >> cnt;
    for (ll j = 0; j < cnt; ++j) {
      ll bit;
      cin >> bit;
      --bit;
      masks[i] |= (1LL << bit);
    }
  }

  vvl dp(n + 1, vl(MASK + 10, +INF));
  dp[0][0] = 0;

  for (ll i = 0; i < m; ++i) {
    for (ll mask = 0; mask < MASK; ++mask) {
      upd(dp[i + 1][mask], dp[i][mask]);
      upd(dp[i + 1][mask | masks[i]], dp[i][mask] + costs[i]);
    }
  }
  ll ans = dp[m][(1 << n) - 1];
  cout << (ans == INF ? -1 : ans) << endl;

  print_time();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 238 + 24111997 % 322);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
  cout.flush();
  cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class T> ostream &operator<<(ostream &out, vector<T> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}
template <class T> ostream &operator<<(ostream &out, set<T> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}
template <class L, class R> ostream &operator<<(ostream &out, map<L, R> vec) {
  out << "(";
  for (auto &v : vec)
    out << v << ", ";
  return out << ")";
}

const ll MAXN = 12;
const ll MASK = (1 << MAXN);
const ll INF = 1e12;

void upd(ll &x, ll y) { x = min(x, y); }

int main() {
  cout << fixed << setprecision(30);
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  ll n, m;
  cin >> n >> m;
  vl costs(m);
  vl masks(m);

  for (ll i = 0; i < m; ++i) {
    ll cnt;
    cin >> costs[i] >> cnt;
    for (ll j = 0; j < cnt; ++j) {
      ll bit;
      cin >> bit;
      --bit;
      masks[i] |= (1LL << bit);
    }
  }

  vvl dp(m + 1, vl(MASK + 10, +INF));
  dp[0][0] = 0;

  for (ll i = 0; i < m; ++i) {
    for (ll mask = 0; mask < MASK; ++mask) {
      upd(dp[i + 1][mask], dp[i][mask]);
      upd(dp[i + 1][mask | masks[i]], dp[i][mask] + costs[i]);
    }
  }
  ll ans = dp[m][(1 << n) - 1];
  cout << (ans == INF ? -1 : ans) << endl;

  print_time();
  return 0;
}