Problem p02683 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<set<int>>;

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return GCD(b, a % b);
  }
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int64_t> c(N);
  vector<vector<int>> a(N, vector<int>(M));

  for (int i = 0; i < N; ++i) {
    cin >> c.at(i);
    for (int j = 0; j < M; j++) {
      cin >> a.at(i).at(j);
    }
  }

  int64_t minV = 1200010;
  for (int bits = 0; bits < (1 << N); bits++) {
    auto mask = bitset<12>(bits);
    int64_t sum = 0;
    vector<int> b(M, 0);
    for (int i = 0; i < N; ++i) {
      if (mask.test(i)) {
        sum += c.at(i);
        for (int j = 0; j < M; ++j) {
          b.at(j) += a.at(i).at(j);
        }
      }
    }

    bool flag = true;
    for (int j = 0; j < M; ++j) {
      if (b.at(j) < X) {
        flag = false;
        break;
      }
    }

    if (flag) {
      minV = min(minV, sum);
    }
  }

  if (minV == 1200010) {
    minV = -1;
  }

  cout << minV << endl;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<set<int>>;

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return GCD(b, a % b);
  }
}
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> c(N);
  vector<vector<int>> a(N, vector<int>(N));

  for (int i = 0; i < N; ++i) {
    cin >> c.at(i);
    for (int j = 0; j < M; j++) {
      cin >> a.at(i).at(j);
    }
  }

  int64_t minV = 1200010;
  for (int bits = 0; bits < (1 << N); bits++) {
    auto mask = bitset<12>(bits);
    int64_t sum = 0;
    vector<int> b(M, 0);
    for (int i = 0; i < N; ++i) {
      if (mask.test(i)) {
        sum += c.at(i);
        for (int j = 0; j < M; ++j) {
          b.at(j) += a.at(i).at(j);
        }
      }
    }

    bool flag = true;
    for (int i = 0; i < M; ++i) {
      if (b.at(i) < X) {
        flag = false;
        break;
      }
    }

    if (flag) {
      minV = min(minV, sum);
    }
  }

  if (minV == 1200010) {
    minV = -1;
  }

  cout << minV << endl;
}