prithivMLmods/Coder-Stat huggingface dataset:
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define x first
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
  IOS int N, M;
  cin >> N >> M;
  int arr[M];
  int brr[M];
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    arr[i] = a;
    for (int j = 0; j < b; j++) {
      int e;
      cin >> e;
      e--;
      brr[i] |= (1 << e);
    }
  }
  int dp[(1 << N) + 2];
  for (int i = 0; i < (1 << N); i++)
    dp[i] = mod;
  dp[0] = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < (1 << N); j++) {
      dp[j | brr[i]] = min(dp[j | brr[i]], dp[j] + arr[i]);
    }
  }
  cout << (dp[(1 << N) - 1] == mod ? -1 : dp[(1 << N) - 1]);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define INF 1000000000000000000
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define x first
#define y second
const int maxx = 1000006;
const int maxlog = 20;
const ll mod = 1000000007;
int arr[maxx];

int main() {
  IOS int N, M;
  cin >> N >> M;
  int arr[M];
  int brr[M];
  for (int i = 0; i < M; i++)
    brr[i] = 0;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    arr[i] = a;
    for (int j = 0; j < b; j++) {
      int e;
      cin >> e;
      e--;
      brr[i] |= (1 << e);
    }
  }
  int dp[(1 << N) + 2];
  for (int i = 0; i < (1 << N); i++)
    dp[i] = mod;
  dp[0] = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < (1 << N); j++) {
      dp[j | brr[i]] = min(dp[j | brr[i]], dp[j] + arr[i]);
    }
  }
  cout << (dp[(1 << N) - 1] == mod ? -1 : dp[(1 << N) - 1]);
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e18;

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

  int N, M;
  cin >> N >> M;
  vector<int> a(M), T(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> a[i] >> k;
    while (k--) {
      int c;
      cin >> c;
      c--;
      T[i] |= 1 << c;
    }
  }

  vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF));
  dp[0][0] = 0;
  for (int i = 0; i < M; i++) {
    for (int S = 0; S < (1 << N); S++) {
      chmin(dp[i + 1][S], dp[i][S]);
      chmin(dp[i + 1][S | T[i]], dp[i][S] + a[i]);
    }
  }
  int ans = dp[N][(1 << N) - 1];
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int INF = 1e18;

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

  int N, M;
  cin >> N >> M;
  vector<int> a(M), T(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> a[i] >> k;
    while (k--) {
      int c;
      cin >> c;
      c--;
      T[i] |= 1 << c;
    }
  }

  vector<vector<int>> dp(M + 1, vector<int>(1 << N, INF));
  dp[0][0] = 0;
  for (int i = 0; i < M; i++) {
    for (int S = 0; S < (1 << N); S++) {
      chmin(dp[i + 1][S], dp[i][S]);
      chmin(dp[i + 1][S | T[i]], dp[i][S] + a[i]);
    }
  }
  int ans = dp[M][(1 << N) - 1];
  cout << (ans == INF ? -1 : ans) << endl;
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF << 1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int N = 12;
const int M = 1001;

int km[M], a[N], n, m;
int dp[M][1 << N];

int solve(int i, int mask) {
  if ((1 << n) == mask + 1)
    return 0;
  if (i == m)
    return INF;
  if (dp[i][mask] != -1)
    return dp[i][mask];
  int ret = INF;
  ret = min(ret, a[i] + solve(i + 1, mask | km[i]));
  ret = min(ret, solve(i + 1, mask));
  return dp[i][mask] = ret;
}

int main() {
  fio;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int b, mask = 0;
    cin >> a[i] >> b;
    for (int j = 0; j < b; j++) {
      int x;
      cin >> x;
      mask |= (1 << x - 1);
    }
    km[i] = mask;
  }
  int ans = solve(0, 0);
  if (ans >= INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF << 1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

const int N = 12;
const int M = 1001;

int km[M], a[M], n, m;
int dp[M][1 << N];

int solve(int i, int mask) {
  if ((1 << n) == mask + 1)
    return 0;
  if (i == m)
    return INF;
  if (dp[i][mask] != -1)
    return dp[i][mask];
  int ret = INF;
  ret = min(ret, a[i] + solve(i + 1, mask | km[i]));
  ret = min(ret, solve(i + 1, mask));
  return dp[i][mask] = ret;
}

int main() {
  fio;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int b, mask = 0;
    cin >> a[i] >> b;
    for (int j = 0; j < b; j++) {
      int x;
      cin >> x;
      mask |= (1 << x - 1);
    }
    km[i] = mask;
  }
  int ans = solve(0, 0);
  if (ans >= INF)
    ans = -1;
  cout << ans << endl;
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_N = 15;
int c[Max_N][Max_N];
const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) cin >> c[i][j];
    rep(j, b[i]) c[i][j]--;
  }
  vector<int> dp(1 << N, INF);
  dp[0] = 0;
  rep(bit, 1 << N) {
    rep(i, M) {
      bool rev = true;
      rep(j, b[i]) {
        if (!(bit & 1 << c[i][j])) {
          rev = false;
          break;
        }
      }
      if (!rev)
        continue;
      rep(j, 1 << b[i]) {
        int bit_prev = bit;
        rep(k, b[i]) if (j & 1 << k) bit_prev -= 1 << c[i][k];
        dp[bit] = min(dp[bit], dp[bit_prev] + a[i]);
      }
    }
  }
  if (dp[(1 << N) - 1] == INF)
    cout << -1 << endl;
  else
    cout << dp[(1 << N) - 1] << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;
const int Max_N = 15;
const int Max_M = 1e3 + 5;
int c[Max_M][Max_N];
const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) cin >> c[i][j];
    rep(j, b[i]) c[i][j]--;
  }
  vector<int> dp(1 << N, INF);
  dp[0] = 0;
  rep(bit, 1 << N) {
    rep(i, M) {
      bool rev = true;
      rep(j, b[i]) {
        if (!(bit & 1 << c[i][j])) {
          rev = false;
          break;
        }
      }
      if (!rev)
        continue;
      rep(j, 1 << b[i]) {
        int bit_prev = bit;
        rep(k, b[i]) if (j & 1 << k) bit_prev -= 1 << c[i][k];
        dp[bit] = min(dp[bit], dp[bit_prev] + a[i]);
      }
    }
  }
  if (dp[(1 << N) - 1] == INF)
    cout << -1 << endl;
  else
    cout << dp[(1 << N) - 1] << endl;

  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dp[10000];
void chmin(int &a, int b) { a = a > b ? b : a; }
int main() {
  int N, M, ans = 0;
  long Inf = 1e9;
  cin >> N >> M;
  long a[M], b[M], d[M];
  long c[M][12];
  rep(i, M) d[i] = 0;
  rep(i, 10000) dp[i] = Inf;
  dp[0] = 0;
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) cin >> c[i][j];
    rep(j, b[i]) d[i] += pow(2, c[i][j]);
  }
  rep(j, M) rep(i, 10000) { chmin(dp[i | d[j]], dp[i] + a[j]); }
  for (int i = 1; i <= N; i++)
    ans += pow(2, i);
  if (dp[ans] == Inf)
    cout << "-1" << endl;
  else
    cout << dp[ans] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dp[10000];
void chmin(int &a, int b) { a = a > b ? b : a; }
int main() {
  int N, M, ans = 0;
  long Inf = 1e9;
  cin >> N >> M;
  long a[M], b[M], d[M];
  long c[M][12];
  rep(i, M) d[i] = 0;
  rep(i, 10000) dp[i] = Inf;
  dp[0] = 0;
  rep(i, M) {
    cin >> a[i] >> b[i];
    rep(j, b[i]) cin >> c[i][j];
    rep(j, b[i]) d[i] += pow(2, c[i][j]);
  }
  rep(j, M) rep(i, 8192) { chmin(dp[i | d[j]], dp[i] + a[j]); }
  for (int i = 1; i <= N; i++)
    ans += pow(2, i);
  if (dp[ans] == Inf)
    cout << "-1" << endl;
  else
    cout << dp[ans] << endl;
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void) {
  int n, m;
  cin >> n >> m;
  vi a(m);
  vi b(m);
  vii c(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    c[i] = vi(b[i]);
    rep(j, b[i]) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  vi dp((int)pow(2, n), 7000000);
  dp[0] = 0;
  rep(j, m) rep(i, (int)pow(2, n)) {
    int next = 0;
    rep(k, b[j]) {
      if ((i / ((int)pow(2, c[j][k]))) % 2 == 0) {
        next += (int)pow(2, c[j][k]);
      }
    }
    dp[i + next] = min(dp[i + next], dp[i] + a[j]);
  }
  /*rep(i,(int)pow(2,n))cout<<dp[i]<<" ";
  cout<<endl;*/
  if (dp[(int)pow(2, n) - 1] == 7000000) {
    cout << -1;
  } else {
    cout << dp[(int)pow(2, n) - 1];
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void) {
  int n, m;
  cin >> n >> m;
  vi a(m);
  vi b(m);
  vii c(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    c[i] = vi(b[i]);
    rep(j, b[i]) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  vi dp((int)pow(2, n), 7000000);
  dp[0] = 0;
  rep(j, m) rep(i, (int)pow(2, n)) {
    int next = 0;
    if (dp[i] == 7000000)
      continue;
    rep(k, b[j]) {
      if ((i / ((int)pow(2, c[j][k]))) % 2 == 0) {
        next += (int)pow(2, c[j][k]);
      }
    }
    dp[i + next] = min(dp[i + next], dp[i] + a[j]);
  }
  /*rep(i,(int)pow(2,n))cout<<dp[i]<<" ";
  cout<<endl;*/
  if (dp[(int)pow(2, n) - 1] == 7000000) {
    cout << -1;
  } else {
    cout << dp[(int)pow(2, n) - 1];
  }
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 12, M = 1010;
int dp[1 << N];
int mask[M], cost[M];
int n, m;

int rec(int mask_) {
  if (__builtin_popcount(mask_) == n) {
    return 0;
  }
  if (dp[mask_] != -1)
    return dp[mask_];
  int res = int(1e9);
  for (int i = 0; i < m; ++i) {
    if ((mask_ & mask[i]) == mask[i])
      continue;
    res = min(res, cost[i] + rec(mask_ | mask[i]));
  }
  return dp[mask_] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < m; ++i) {
    mask[i] = 0;
    int x;
    cin >> cost[i] >> x;
    for (int j = 0; j < x; ++j) {
      int y;
      cin >> y;
      mask[i] |= (1 << y);
    }
  }
  int res = rec(0);
  cout << (res == int(1e9) ? -1 : res) << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 13, M = 1010;
int dp[1 << N];
int mask[M], cost[M];
int n, m;

int rec(int mask_) {
  if (__builtin_popcount(mask_) == n) {
    return 0;
  }
  if (dp[mask_] != -1)
    return dp[mask_];
  int res = int(1e9);
  for (int i = 0; i < m; ++i) {
    if ((mask_ & mask[i]) == mask[i])
      continue;
    res = min(res, cost[i] + rec(mask_ | mask[i]));
  }
  return dp[mask_] = res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < m; ++i) {
    mask[i] = 0;
    int x;
    cin >> cost[i] >> x;
    for (int j = 0; j < x; ++j) {
      int y;
      cin >> y;
      mask[i] |= (1 << y);
    }
  }
  int res = rec(0);
  cout << (res == int(1e9) ? -1 : res) << '\n';
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(pow(2, n), 10000000);
  for (int i = 0; i < m; i++) {
    int c, d;
    cin >> c >> d;
    int n = 0;
    for (int j = 0; j < d; j++) {
      int k;
      cin >> k;
      n |= (1 << k - 1);
    }
    a.at(n) = min(a.at(n), c);
  }
  for (int h = 0; h < 12; h++) {
    for (int i = 0; i < pow(2, n); i++) {
      for (int j = i + 1; j < pow(2, n); j++) {
        a.at(i | j) = min(a.at(i | j), a.at(i) + a.at(j));
      }
    }
  }
  int ans = a.at(pow(2, n) - 1);
  if (ans == 10000000)
    ans = -1;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(pow(2, n), 10000000);
  for (int i = 0; i < m; i++) {
    int c, d;
    cin >> c >> d;
    int n = 0;
    for (int j = 0; j < d; j++) {
      int k;
      cin >> k;
      n |= (1 << k - 1);
    }
    a.at(n) = min(a.at(n), c);
  }
  for (int h = 1; h < 12; ++h) {

    for (int i = 0; i < pow(2, n); ++i) {
      if (__builtin_popcount(i) == h) {
        for (int j = 0; j < pow(2, n); ++j) {

          a.at(i | j) = min(a.at(i | j), a.at(i) + a.at(j));
        }
      }
    }
  }
  int ans = a.at(pow(2, n) - 1);
  if (ans == 10000000)
    ans = -1;
  cout << ans << endl;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
const int maxn = (int)1e5 + 1;
const int inf = (int)1e9 + 7;

int m, b[1111], u[1111], p[1111], a[1111];

int c[13][13];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[(1 << 13)];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    for (int j = 1; j <= b[i]; j++) {
      cin >> c[i][j];
    }
  }
  fill(dp, dp + (1 << 12), inf);
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    for (int i = 1; i <= m; i++) {
      int nmask = mask;
      for (int j = 1; j <= b[i]; j++) {
        if ((nmask >> (c[i][j] - 1)) & 1) {
          nmask &= ~(1 << c[i][j] - 1);
        }
      }
      /*for(int j = 0; j <= nmask; j++){
          cout << ((nmask >> j) % 2);
      }*/
      dp[mask] = min(dp[mask], dp[nmask] + a[i]);
    }
    // cout << dp[mask] << endl;
  }
  if (dp[(1 << n) - 1] == inf) {
    cout << -1;
    return 0;
  }
  cout << dp[(1 << n) - 1];
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
const int maxn = (int)1e5 + 1;
const int inf = (int)1e9 + 7;

int m, b[1111], u[1111], p[1111], a[1111];

int c[1111][13];

int cnt[maxn];

string s, t;

int ans = 0, sum1, sum2, sum3;

ll n, k;

int dp[(1 << 13)];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    for (int j = 1; j <= b[i]; j++) {
      cin >> c[i][j];
    }
  }
  fill(dp, dp + (1 << 12), inf);
  dp[0] = 0;
  for (int mask = 1; mask < (1 << n); mask++) {
    for (int i = 1; i <= m; i++) {
      int nmask = mask;
      for (int j = 1; j <= b[i]; j++) {
        if ((nmask >> (c[i][j] - 1)) & 1) {
          nmask &= ~(1 << c[i][j] - 1);
        }
      }
      /*for(int j = 0; j <= nmask; j++){
          cout << ((nmask >> j) % 2);
      }*/
      dp[mask] = min(dp[mask], dp[nmask] + a[i]);
    }
    // cout << dp[mask] << endl;
  }
  if (dp[(1 << n) - 1] == inf) {
    cout << -1;
    return 0;
  }
  cout << dp[(1 << n) - 1];
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define ll long long
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)

using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> A(M);
  vector<vector<int>> C(M);
  repp(i, 0, M) {
    int b;
    cin >> A[i] >> b;
    repp(j, 0, b) {
      int c;
      cin >> c;
      C[i].push_back(c);
    }
  }

  const long long INF = 1LL << 32;

  long long dp[110][1 << 12];
  Fill(dp, INF);
  dp[0][0] = 0;

  repp(i, 0, M) {
    int bit = 0;
    repp(j, 0, (int)C[i].size()) bit |= (1 << (C[i][j] - 1));
    repp(j, 0, 1 << N) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    repp(j, 0, 1 << N) dp[i + 1][bit | j] =
        min(dp[i + 1][bit | j], dp[i][j] + A[i]);
  }

  long long result = dp[M][(1 << N) - 1] == INF ? -1 : dp[M][(1 << N) - 1];
  cout << result << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define ll long long
#define repp(i, a, b) for (int i = (int)a; i < (int)b; ++i)

using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> A(M);
  vector<vector<int>> C(M);
  repp(i, 0, M) {
    int b;
    cin >> A[i] >> b;
    repp(j, 0, b) {
      int c;
      cin >> c;
      C[i].push_back(c);
    }
  }

  const long long INF = 1LL << 32;

  long long dp[1010][1 << 12];
  Fill(dp, INF);
  dp[0][0] = 0;

  repp(i, 0, M) {
    int bit = 0;
    repp(j, 0, (int)C[i].size()) bit |= (1 << (C[i][j] - 1));
    repp(j, 0, 1 << N) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    repp(j, 0, 1 << N) dp[i + 1][bit | j] =
        min(dp[i + 1][bit | j], dp[i][j] + A[i]);
  }

  long long result = dp[M][(1 << N) - 1] == INF ? -1 : dp[M][(1 << N) - 1];
  cout << result << endl;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int N, M, a[1111], b[1111], c, d[1111], T;

long long memo[22][4444];

long long dfs(int i, int j) {
  if (j == T)
    return 0;

  if (i == M)
    return INF;

  if (memo[i][j] < 0x3f3f3f3f3f3f3f3fLL)
    return memo[i][j];

  long long x = dfs(i + 1, j | d[i]) + a[i];
  long long y = dfs(i + 1, j);

  return memo[i][j] = std::min(x, y);
}

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> M;

  for (int i = 0; i < M; i++) {
    std::cin >> a[i] >> b[i];

    d[i] = 0;

    for (int j = 0; j < b[i]; j++) {
      std::cin >> c;

      c--;

      d[i] |= 1 << c;
    }
  }

  T = (1 << N) - 1;

  memset(memo, 0x3f, sizeof(memo));

  long long x = dfs(0, 0);

  std::cout << (x < INF ? x : -1) << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)

int N, M, a[1111], b[1111], c, d[1111], T;

long long memo[1111][4444];

long long dfs(int i, int j) {
  if (j == T)
    return 0;

  if (i == M)
    return INF;

  if (memo[i][j] < 0x3f3f3f3f3f3f3f3fLL)
    return memo[i][j];

  long long x = dfs(i + 1, j | d[i]) + a[i];
  long long y = dfs(i + 1, j);

  return memo[i][j] = std::min(x, y);
}

int main(int argc, char **argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  std::cin >> N >> M;

  for (int i = 0; i < M; i++) {
    std::cin >> a[i] >> b[i];

    d[i] = 0;

    for (int j = 0; j < b[i]; j++) {
      std::cin >> c;

      c--;

      d[i] |= 1 << c;
    }
  }

  T = (1 << N) - 1;

  memset(memo, 0x3f, sizeof(memo));

  long long x = dfs(0, 0);

  std::cout << (x < INF ? x : -1) << std::endl;

  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long lli;
const int INF = 1e9 + 19;
const int maxn = 12;
const int maxm = 1005;
int n, m;
int c[maxn], x[maxm];

int dp[(1 << maxn) + 5];

void ReadInput() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> c[i] >> k;
    x[i] = 0;
    for (; k > 0; --k) {
      int a;
      cin >> a;
      --a;
      x[i] |= (1 << a);
    }
  }
}

void Solve() {
  fill(begin(dp), end(dp), INF);
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    if (dp[mask] == INF)
      continue;

    for (int i = 0; i < m; ++i) {
      int nmask = mask | x[i];
      dp[nmask] = min(dp[nmask], dp[mask] + c[i]);
    }
  }

  if (dp[(1 << n) - 1] == INF)
    cout << "-1\n";
  else
    cout << dp[(1 << n) - 1] << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ReadInput();
  Solve();
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long lli;
const int INF = 1e9 + 19;
const int maxn = 12;
const int maxm = 1005;
int n, m;
int c[maxm], x[maxm];

int dp[(1 << maxn) + 5];

void ReadInput() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> c[i] >> k;
    x[i] = 0;
    for (; k > 0; --k) {
      int a;
      cin >> a;
      --a;
      x[i] |= (1 << a);
    }
  }
}

void Solve() {
  fill(begin(dp), end(dp), INF);
  dp[0] = 0;
  for (int mask = 0; mask < (1 << n); ++mask) {
    if (dp[mask] == INF)
      continue;

    for (int i = 0; i < m; ++i) {
      int nmask = mask | x[i];
      dp[nmask] = min(dp[nmask], dp[mask] + c[i]);
    }
  }

  if (dp[(1 << n) - 1] == INF)
    cout << "-1\n";
  else
    cout << dp[(1 << n) - 1] << '\n';
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ReadInput();
  Solve();
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

#define INF 0x3f3f3f3f

int N, M;

int cost[1001];  // custo de cada chave
int chave[1001]; // baus que cada chave abre
int memo[1001][9000];
int total; // bits de baus

int dp(int key, int baus) {

  if (key == M) {
    if (baus == total)
      return 0;
    else
      return INF;
  }

  // if(memo[key][baus] != -1) return memo[key][baus];

  // usando essa chave
  int a = dp(key + 1, baus | chave[key]) + cost[key];

  // sem usar essa chave
  int b = dp(key + 1, baus);

  int res = min(a, b);
  memo[key][baus] = res;

  return res;
}

int main() {

  cin >> N >> M;
  memset(memo, -1, sizeof(memo));

  for (int i = 0; i < N; i++) {
    total |= 1 << i;
  }

  for (int i = 0; i < M; i++) {
    int custo, qtd;

    cin >> custo >> qtd;
    cost[i] = custo;

    int bau;
    for (int x = 0; x < qtd; x++) {
      cin >> bau;
      chave[i] |= 1 << (bau - 1);
    }
  }

  int res = dp(0, 0);
  if (res == INF)
    cout << -1 << endl;
  else
    cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define INF 0x3f3f3f3f

int N, M;

int cost[1001];  // custo de cada chave
int chave[1001]; // baus que cada chave abre
int memo[1001][9000];
int total; // bits de baus

int dp(int key, int baus) {

  if (key == M) {
    if (baus == total)
      return 0;
    else
      return INF;
  }

  if (memo[key][baus] != -1)
    return memo[key][baus];

  // usando essa chave
  int a = dp(key + 1, baus | chave[key]) + cost[key];

  // sem usar essa chave
  int b = dp(key + 1, baus);

  int res = min(a, b);
  memo[key][baus] = res;

  return res;
}

int main() {

  cin >> N >> M;
  memset(memo, -1, sizeof(memo));

  for (int i = 0; i < N; i++) {
    total |= 1 << i;
  }

  for (int i = 0; i < M; i++) {
    int custo, qtd;

    cin >> custo >> qtd;
    cost[i] = custo;

    int bau;
    for (int x = 0; x < qtd; x++) {
      cin >> bau;
      chave[i] |= 1 << (bau - 1);
    }
  }

  int res = dp(0, 0);
  if (res == INF)
    cout << -1 << endl;
  else
    cout << res << endl;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
#include <string.h>

int a[100];
int b[100];
int c[100];
int dp[1 << 12];

int main() {

  int n, m, C;

  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
    for (int j = 0; j < b[i]; j++) {
      scanf("%d", &C);
      C--;
      c[i] |= 1 << C;
    }
  }

  memset(dp, 0x7f, sizeof(dp));

  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < (1 << n); j++) {
      if (dp[j] >= 0) {
        dp[j | c[i]] = std::min(dp[j] + a[i], dp[j | c[i]]);
      }
    }
  }

  if (dp[(1 << n) - 1] == 2139062143)
    printf("-1");
  else
    printf("%d", dp[(1 << n) - 1]);
  puts("");

  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <string.h>

int a[1005];
int b[1005];
int c[1005];
int dp[1 << 12];

int main() {

  int n, m, C;

  scanf("%d%d", &n, &m);

  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a[i], &b[i]);
    for (int j = 0; j < b[i]; j++) {
      scanf("%d", &C);
      C--;
      c[i] |= 1 << C;
    }
  }

  memset(dp, 0x7f, sizeof(dp));

  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < (1 << n); j++) {
      if (dp[j] >= 0) {
        dp[j | c[i]] = std::min(dp[j] + a[i], dp[j | c[i]]);
      }
    }
  }

  if (dp[(1 << n) - 1] == 2139062143)
    printf("-1");
  else
    printf("%d", dp[(1 << n) - 1]);
  puts("");

  return 0;
}
Problem p02901 (Python)

Buggy submission (status: Runtime Error):
def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float("inf")

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dpi[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()


Fixed submission:
def read_key():
    a, _ = map(int, input().split())
    m = 0
    for c in map(int, input().split()):
        m |= 1 << (c - 1)
    return (a, m)


def main():
    INF = float("inf")

    N, M = map(int, input().split())
    keys = [read_key() for _ in range(M)]

    dp = [[INF] * (1 << N) for _ in range(M + 1)]

    dp[0][0] = 0
    for i in range(M):
        a, m = keys[i]
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(1 << N):
            if dpi[j] == INF:
                continue
            if dpi[j] + a < dpi1[j | m]:
                dpi1[j | m] = dpi[j] + a
            if dpi[j] < dpi1[j]:
                dpi1[j] = dpi[j]

    if dp[M][(1 << N) - 1] == INF:
        print(-1)
    else:
        print(dp[M][(1 << N) - 1])


main()
Problem p02901 (Python)

Buggy submission (status: Time Limit Exceeded):
INF = float("inf")

N, M = map(int, input().split())

dp = [INF] * (2**N)
dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    C = [int(i) for i in input().split()]
    mask = sum(1 << (c - 1) for c in C)
    for i in range(len(dp)):
        dp[i | mask] = min(dp[i | mask], dp[i] + a)

ans = dp[-1]
print(-1 if ans == INF else ans)


Fixed submission:
INF = float("inf")

N, M = map(int, input().split())

dp = [INF] * (2**N)
dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    C = [int(i) for i in input().split()]
    mask = sum(1 << (c - 1) for c in C)
    for i in range(len(dp)):
        if dp[i | mask] > dp[i] + a:
            dp[i | mask] = dp[i] + a

ans = dp[-1]
print(-1 if ans == INF else ans)
Problem p02901 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    n, m = map(int, input().split())
    a = []
    c = []
    dp = [10**7 for j in range(2**n)]
    dp[0] = 0
    for _ in range(m):
        a, b = map(int, input().split())
        sc = list(map(int, input().split()))
        c = 0
        for j in sc:
            c += 2 ** (j - 1)
        for j in range(2**n):
            dp[int(j | c)] = min(dp[int(j | c)], dp[j] + a)

    if dp[2**n - 1] == 10**7:
        print(-1)
    else:
        print(dp[2**n - 1])


main()


Fixed submission:
def main():
    n, m = map(int, input().split())
    a = []
    c = []
    dp = [10**7 for j in range(2**n)]
    dp[0] = 0
    for _ in range(m):
        a, b = map(int, input().split())
        sc = list(map(int, input().split()))
        c = 0
        for j in sc:
            c += 2 ** (j - 1)
        for j in range(2**n):
            dp[j | c] = min(dp[j | c], dp[j] + a)

    if dp[2**n - 1] == 10**7:
        print(-1)
    else:
        print(dp[2**n - 1])


main()
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define pb push_back
#define fi first
#define se second
#define INF (ll)(1e18 + 7)
#define MOD (ll)(1e9 + 7)

const int N = 5e3 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a, b, c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], p[N], dp[N][N];
string str;
bool h[N];
pll pp[N];
vll v;

ll f(ll cur, ll mask) {
  if (cur == m + 1)
    return (mask == (1 << n) - 1 ? 0 : INF);
  ll &r = dp[cur][mask];
  if (~r)
    return r;
  r = INF;
  r = min(r, f(cur + 1, mask));
  r = min(r, f(cur + 1, mask | ar[cur]) + p[cur]);
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);

  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i] >> a;
    for (int j = 1; j <= a; j++) {
      cin >> k;
      ar[i] |= (1 << (k - 1));
    }
  }
  ans = f(1, 0);
  if (ans >= INF)
    ans = -1;
  cout << ans;
}

Fixed submission:
//
//  sublime text 3,
//  emre yazicioglu
//

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define pb push_back
#define fi first
#define se second
#define INF (ll)(1e18 + 7)
#define MOD (ll)(1e9 + 7)

const int N = 5e3 + 7;
ll mn = INF, mx = -INF;
ll n, m, k, s, q, t;
ll a, b, c, d, e;
ll ans, cur, sum, cnt;
ll ar[N], p[N], dp[N][N];
string str;
bool h[N];
pll pp[N];
vll v;

ll f(ll cur, ll mask) {
  if (cur == m + 1)
    return (mask == (1 << n) - 1 ? 0 : INF);
  ll &r = dp[cur][mask];
  if (~r)
    return r;
  r = INF;
  r = min(r, f(cur + 1, mask));
  r = min(r, f(cur + 1, mask | ar[cur]) + p[cur]);
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // freopen("../in.txt","r",stdin);
  // freopen("../out.txt","w",stdout);

  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p[i] >> a;
    for (int j = 1; j <= a; j++) {
      cin >> k;
      ar[i] |= (1 << (k - 1));
    }
  }
  ans = f(1, 0);
  if (ans >= INF)
    ans = -1;
  cout << ans;
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))

using ll = std::int64_t;
using P = std::tuple<int, int>;

constexpr int INF = 1'000'000'000;
int N, M;
int A[1100], B[1100], C[1100];
int dp[1100][1 << 12];

int rec(int i, int s) {
  if (s + 1 == (1 << N)) {
    return 0;
  }

  if (i == M) {
    return INF;
  }

  int res = std::min(rec(i + 1, s), rec(i + 1, s | C[i]) + A[i]);
  return dp[i][s] = res;
}

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

  std::cin >> N >> M;

  for (int i = 0; i < M; ++i) {
    std::cin >> A[i] >> B[i];

    for (int j = 0; j < B[i]; ++j) {
      int c;
      std::cin >> c;

      c -= 1;

      C[i] |= (1 << c);
    }
  }

  memset(dp, -1, sizeof(dp));

  int res = rec(0, 0);

  if (res >= INF) {
    res = -1;
  }

  std::cout << res << std::endl;
}


Fixed submission:
#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))

using ll = std::int64_t;
using P = std::tuple<int, int>;

constexpr int INF = 1'000'000'000;
int N, M;
int A[1100], B[1100], C[1100];
int dp[1100][1 << 12];

int rec(int i, int s) {
  if (s + 1 == (1 << N)) {
    return 0;
  }

  if (i == M) {
    return INF;
  }

  if (dp[i][s] != -1) {
    return dp[i][s];
  }

  int res = std::min(rec(i + 1, s), rec(i + 1, s | C[i]) + A[i]);
  return dp[i][s] = res;
}

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

  std::cin >> N >> M;

  for (int i = 0; i < M; ++i) {
    std::cin >> A[i] >> B[i];

    for (int j = 0; j < B[i]; ++j) {
      int c;
      std::cin >> c;

      c -= 1;

      C[i] |= (1 << c);
    }
  }

  memset(dp, -1, sizeof(dp));

  int res = rec(0, 0);

  if (res >= INF) {
    res = -1;
  }

  std::cout << res << std::endl;
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define ll long long int
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define sep(i, b, a) for (ll i = b - 1; i >= a; i--)
#define vi vector<ll>
#define hell 1000000007
#define pii pair<ll, ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

ll dp[1001][1 << 12];

ll helper(vi &a, vi &b, ll st, ll mask, ll reqmask) {
  if (mask == reqmask)
    return 0;
  if (st >= a.size())
    return inf;
  ll ans;
  ans = helper(a, b, st + 1, mask, reqmask);
  ans = min(ans, a[st] + helper(a, b, st + 1, mask | b[st], reqmask));
  return dp[st][mask] = ans;
}

void solve() {
  ll n, m;
  cin >> n >> m;
  vi a, b;
  rep(i, 0, m) {
    vector<bool> v(n, false);
    ll x, y;
    cin >> x >> y;
    rep(i, 0, y) {
      ll p;
      cin >> p;
      v[p - 1] = true;
    }
    ll num = 0;
    rep(i, 0, n) {
      num = num * 2;
      num += v[i];
    }
    a.pb(x);
    b.pb(num);
  }
  ll reqmask = (1 << n) - 1;
  memset(dp, -1, sizeof dp);
  ll ans = helper(a, b, 0, 0, reqmask);
  if (ans == inf)
    ans = -1;
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define ll long long int
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define sep(i, b, a) for (ll i = b - 1; i >= a; i--)
#define vi vector<ll>
#define hell 1000000007
#define pii pair<ll, ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

ll dp[1001][1 << 12];

ll helper(vi &a, vi &b, ll st, ll mask, ll reqmask) {
  if (mask == reqmask)
    return 0;
  if (st >= a.size())
    return inf;
  if (dp[st][mask] != -1)
    return dp[st][mask];
  ll ans;
  ans = helper(a, b, st + 1, mask, reqmask);
  ans = min(ans, a[st] + helper(a, b, st + 1, mask | b[st], reqmask));
  return dp[st][mask] = ans;
}

void solve() {
  ll n, m;
  cin >> n >> m;
  vi a, b;
  rep(i, 0, m) {
    vector<bool> v(n, false);
    ll x, y;
    cin >> x >> y;
    rep(i, 0, y) {
      ll p;
      cin >> p;
      v[p - 1] = true;
    }
    ll num = 0;
    rep(i, 0, n) {
      num = num * 2;
      num += v[i];
    }
    a.pb(x);
    b.pb(num);
  }
  ll reqmask = (1 << n) - 1;
  memset(dp, -1, sizeof dp);
  ll ans = helper(a, b, 0, 0, reqmask);
  if (ans == inf)
    ans = -1;
  cout << ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
const ll INF = 999999999999;
ll dp[1 << 20];

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<vector<int>> c(m);

  for (int i = 0; i < m; i++) {
    int A, b;
    cin >> A >> b;
    a[i] = A;
    for (int j = 0; j < b; j++) {
      int _;
      cin >> _;
      _--;
      c[i].push_back(_);
    }
  }

  queue<int> q;
  q.push(0);
  for (int i = 0; i < 1 << n; i++)
    dp[i] = INF;
  dp[0] = 0;

  while (!q.empty()) {
    int bit = q.front();
    q.pop();
    for (int i = 0; i < m; i++) {
      int nbit = 0;
      for (int j : c[i]) {
        nbit += 1 << j;
      }
      if (bit == (bit | nbit))
        continue;
      nbit = bit | nbit;
      q.push(nbit);
      dp[nbit] = min(dp[nbit], dp[bit] + a[i]);
    }
  }
  if (dp[(1 << n) - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[(1 << n) - 1] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
const ll INF = 999999999999;
ll dp[1 << 20];

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<vector<int>> c(m);

  for (int i = 0; i < m; i++) {
    int A, b;
    cin >> A >> b;
    a[i] = A;
    for (int j = 0; j < b; j++) {
      int _;
      cin >> _;
      _--;
      c[i].push_back(_);
    }
  }

  queue<int> q;
  q.push(0);
  for (int i = 0; i < 1 << n; i++)
    dp[i] = INF;
  dp[0] = 0;

  while (!q.empty()) {
    int bit = q.front();
    q.pop();
    for (int i = 0; i < m; i++) {
      int nbit = 0;
      for (int j : c[i]) {
        nbit += 1 << j;
      }
      if (bit == (bit | nbit))
        continue;
      nbit = bit | nbit;
      if (dp[nbit] > dp[bit] + a[i]) {
        dp[nbit] = dp[bit] + a[i];
        q.push(nbit);
      }
    }
  }
  if (dp[(1 << n) - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[(1 << n) - 1] << endl;
  }
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define INF 10000000000000
#define MK2DV(v, row, col, val) vector<vector<ll>> v(row, vector<ll>(col, val))
using namespace std;
ll findmin(ll a, ll b) {
  if (a < b)
    return a;
  return b;
}
ll fuc(ll i, ll have, ll *give, ll *cost, ll m, ll n, vector<vector<ll>> &dp) {
  if (have == n) {
    return 0;
  }
  if (i == m) {
    return INF;
  }
  if (dp[i][have] != -1) {
    return dp[i][have];
  }
  ll ans =
      findmin(fuc(i + 1, have, give, cost, m, n, dp),
              fuc(i + 1, (have | give[i]), give, cost, m, n, dp) + cost[i]);
  dp[i][have] = ans;
  return ans;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll give[m];
  ll cost[m];
  ll netreq = (1LL << n) - 1;
  MK2DV(dp, n + 5, netreq + 5, -1);
  for (ll i = 0; i < m; i++) {
    give[i] = 0;
    ll a, b;
    cin >> a >> b;
    cost[i] = a;
    for (ll j = 0; j < b; j++) {
      ll key;
      cin >> key;
      key--;
      ll mask = (1LL << key);
      give[i] = (give[i] | mask);
    }
  }
  ll ans = fuc(0, 0, give, cost, m, netreq, dp);
  if (ans >= INF)
    ans = -1;
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define INF 10000000000000
#define MK2DV(v, row, col, val) vector<vector<ll>> v(row, vector<ll>(col, val))
using namespace std;
ll findmin(ll a, ll b) {
  if (a < b)
    return a;
  return b;
}
ll fuc(ll i, ll have, ll *give, ll *cost, ll m, ll n, vector<vector<ll>> &dp) {
  if (have == n) {
    return 0;
  }
  if (i == m) {
    return INF;
  }
  if (dp[i][have] != -1) {
    return dp[i][have];
  }
  ll ans =
      findmin(fuc(i + 1, have, give, cost, m, n, dp),
              fuc(i + 1, (have | give[i]), give, cost, m, n, dp) + cost[i]);
  dp[i][have] = ans;
  return ans;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll give[m];
  ll cost[m];
  ll netreq = (1LL << n) - 1;
  MK2DV(dp, m + 5, netreq + 5, -1);
  for (ll i = 0; i < m; i++) {
    give[i] = 0;
    ll a, b;
    cin >> a >> b;
    cost[i] = a;
    for (ll j = 0; j < b; j++) {
      ll key;
      cin >> key;
      key--;
      ll mask = (1LL << key);
      give[i] = (give[i] | mask);
    }
  }
  ll ans = fuc(0, 0, give, cost, m, netreq, dp);
  if (ans >= INF)
    ans = -1;
  cout << ans << '\n';
  return 0;
}
Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], d[m];
  fill(d, d + n, 0);
  for (int i = 0; i < m; i++) {
    int b;
    cin >> a[i] >> b;
    for (int j = 0; j < b; j++) {
      int c;
      cin >> c;
      d[i] += pow(2, c - 1);
    }
  }
  int max_state = pow(2, n);
  int dp[m + 1][max_state];
  int inf = 1000000000;
  for (int i = 0; i < m + 1; i++) {
    for (int j = 0; j < max_state; j++) {
      dp[i][j] = inf;
    }
  }
  for (int i = 0; i < m + 1; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i < m + 1; i++) {
    for (int j = 1; j < max_state; j++) {
      dp[i][j] = dp[i - 1][j];
    }
    for (int j = 0; j < max_state; j++) {
      int k = j | d[i - 1];
      if (dp[i][k] > dp[i - 1][j] + a[i - 1])
        dp[i][k] = dp[i - 1][j] + a[i - 1];
    }
  }
  if (dp[m][max_state - 1] == inf)
    cout << -1 << endl;
  else
    cout << dp[m][max_state - 1] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int a[m], d[m];
  fill(d, d + m, 0);
  for (int i = 0; i < m; i++) {
    int b;
    cin >> a[i] >> b;
    for (int j = 0; j < b; j++) {
      int c;
      cin >> c;
      d[i] += pow(2, c - 1);
    }
  }
  int max_state = pow(2, n);
  int dp[m + 1][max_state];
  int inf = 1000000000;
  for (int i = 0; i < m + 1; i++) {
    for (int j = 0; j < max_state; j++) {
      dp[i][j] = inf;
    }
  }
  for (int i = 0; i < m + 1; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i < m + 1; i++) {
    for (int j = 1; j < max_state; j++) {
      dp[i][j] = dp[i - 1][j];
    }
    for (int j = 0; j < max_state; j++) {
      int k = j | d[i - 1];
      if (dp[i][k] > dp[i - 1][j] + a[i - 1])
        dp[i][k] = dp[i - 1][j] + a[i - 1];
    }
  }
  if (dp[m][max_state - 1] == inf)
    cout << -1 << endl;
  else
    cout << dp[m][max_state - 1] << endl;
  return 0;
}