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

Buggy submission (status: Runtime Error):
// 問題URL
//

// 解き方メモ
//

#include <climits>
#include <iostream>
#include <vector>
using namespace std;

#define MAX_SHOP_NUM 100
#define TZ_NUM 10

int main() {
  int n;
  vector<int> f;
  vector<vector<int>> p;
  long long max_sum = LLONG_MIN;

  // input
  cin >> n;

  f.resize(n);
  p.resize(n);

  // Fは２進数表記とする
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < TZ_NUM; j++) {
      int tmp;
      cin >> tmp;

      f[i] <<= 1; // 左シフト
      if (tmp == 1) {
        f[i] += 0x1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    p[i].resize(10);
    for (int j = 0; j < TZ_NUM + 1; j++) {
      cin >> p[i][j];
    }
  }

  // proc
  int tz = 1;
  while (tz < 0x400) { // 11111111までループ

    long long tmp_sum = 0;
    for (int i = 0; i < (int)f.size(); i++) {
      // cout << i << ")";
      int tz_diff = f[i] & tz; // tz_diff:時間帯が重なるビットが1
      int cnt = 0;
      while (tz_diff > 0) {
        cnt += tz_diff & 0x1;
        tz_diff >>= 1;
        // cout << cnt << ",";
      }
      tmp_sum += p[i][cnt];
    }
    // cout << tz << "," << ","<< tmp_sum << endl;
    max_sum = max(max_sum, tmp_sum);
    tz += 0x1;
  }
  // cout << p[1][0] << endl;;

  cout << max_sum << endl;

  return 0;
}


Fixed submission:
// 問題URL
//

// 解き方メモ
//

#include <climits>
#include <iostream>
#include <vector>
using namespace std;

#define MAX_SHOP_NUM 100
#define TZ_NUM 10

int main() {
  int n;
  vector<int> f;
  vector<vector<int>> p;
  long long max_sum = LLONG_MIN;

  // input
  cin >> n;

  f.resize(n);
  p.resize(n);

  // Fは２進数表記とする
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < TZ_NUM; j++) {
      int tmp;
      cin >> tmp;

      f[i] <<= 1; // 左シフト
      if (tmp == 1) {
        f[i] += 0x1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    p[i].resize(TZ_NUM + 1);
    for (int j = 0; j < TZ_NUM + 1; j++) {
      cin >> p[i][j];
    }
  }

  // proc
  int tz = 1;
  while (tz < 0x400) { // 11111111までループ

    long long tmp_sum = 0;
    for (int i = 0; i < (int)f.size(); i++) {
      // cout << i << ")";
      int tz_diff = f[i] & tz; // tz_diff:時間帯が重なるビットが1
      int cnt = 0;
      while (tz_diff > 0) {
        cnt += tz_diff & 0x1;
        tz_diff >>= 1;
        // cout << cnt << ",";
      }
      tmp_sum += p[i][cnt];
    }
    // cout << tz << "," << ","<< tmp_sum << endl;
    max_sum = max(max_sum, tmp_sum);
    tz += 0x1;
  }
  // cout << p[1][0] << endl;;

  cout << max_sum << endl;

  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
ll MAX = 9223372036854775807;
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> F(n, vector<ll>(10, 0));
  vector<vector<ll>> P(n, vector<ll>(11, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {

      ll x;
      cin >> x;
      F[i][j] = x;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {

      ll x;
      cin >> x;
      P[i][j] = x;
    }
  }
  ll ans = -1e19;
  ll mask1 = 0;
  bool B = true;
  for (int mask = 1; mask < (1 << 10); mask++) {
    vector<ll> bin(11, 0);
    for (int i = 0; i < 10; i++)
      if (mask & (1 << i)) {
        for (int j = 0; j < n; j++)
          if (F[j][i] == 1)
            bin[j]++;
      }
    ll val = 0;
    for (int i = 0; i < n; i++) {
      val += P[i][bin[i]];
    }
    ans = max(ans, val);
  }

  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
ll MAX = 9223372036854775807;
using namespace std;
int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> F(n, vector<ll>(10, 0));
  vector<vector<ll>> P(n, vector<ll>(11, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {

      ll x;
      cin >> x;
      F[i][j] = x;
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {

      ll x;
      cin >> x;
      P[i][j] = x;
    }
  }
  ll ans = -1e19;
  ll mask1 = 0;
  bool B = true;
  for (int mask = 1; mask < (1 << 10); mask++) {
    vector<ll> bin(n + 1, 0);
    for (int i = 0; i < 10; i++)
      if (mask & (1 << i)) {
        for (int j = 0; j < n; j++)
          if (F[j][i] == 1)
            bin[j]++;
      }
    ll val = 0;
    for (int i = 0; i < n; i++) {
      val += P[i][bin[i]];
    }
    ans = max(ans, val);
  }

  cout << ans;
  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  int n;
  cin >> n;
  vvint f(n, vint(10)), p(n, vint(10));
  rep(i, n) rep(j, 10) cin >> f[i][j];
  rep(i, n) rep(j, 11) cin >> p[i][j];
  int ans = -inf;
  REP(i, 1 << 10) {
    int sum = 0;
    rep(j, n) {
      int ct = 0;
      rep(k, 10) {
        if ((i >> k & 1) && f[j][k])
          ct++;
      }
      sum += p[j][ct];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vout(x) rep(i, x.size()) cout << x[i] << " "
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
  int n;
  cin >> n;
  vvint f(n, vint(10)), p(n, vint(11));
  rep(i, n) rep(j, 10) cin >> f[i][j];
  rep(i, n) rep(j, 11) cin >> p[i][j];
  int ans = -inf;
  REP(i, 1 << 10) {
    int sum = 0;
    rep(j, n) {
      int ct = 0;
      rep(k, 10) {
        if ((i >> k & 1) && f[j][k])
          ct++;
      }
      sum += p[j][ct];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
Problem p03503 (C++)

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

int N;
int F[100][14];
int P[100][15];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 10; ++j)
      scanf("%d", &F[i][j]);

  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 11; ++j)
      scanf("%d", &P[i][j]);

  int res = -(1 << 30);
  for (int b = 1; b < (1 << 30); ++b) {
    int cc = 0;
    for (int i = 0; i < N; ++i) {
      int c = 0;
      for (int j = 0; j < 10; ++j)
        if (((b >> j) & 1) && F[i][j])
          c++;
      cc += P[i][c];
    }
    if (res < cc)
      res = cc;
  }
  printf("%d\n", res);
}


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

int N;
int F[100][14];
int P[100][15];

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 10; ++j)
      scanf("%d", &F[i][j]);

  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 11; ++j)
      scanf("%d", &P[i][j]);

  int res = -(1 << 30);
  for (int b = 1; b < (1 << 10); ++b) {
    int cc = 0;
    for (int i = 0; i < N; ++i) {
      int c = 0;
      for (int j = 0; j < 10; ++j)
        if (((b >> j) & 1) && F[i][j])
          c++;
      cc += P[i][c];
    }
    if (res < cc)
      res = cc;
  }
  printf("%d\n", res);
}
Problem p03503 (C++)

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

// long C(long n, long r);
// long long gcd(long long a, long long b);
// long long lcm(long long a, long long b);

void solve() {
  int n;
  cin >> n;
  bool f[n + 1][11];
  int p[n + 1][11];

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++)
      f[i][j] = false;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++) {
      int _f;
      cin >> _f;
      if (_f == 1)
        f[i][j] = true;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++)
      cin >> p[i][j];
  }

  ll ans = LLONG_MIN;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ll subAns = 0ll;
    vector<int> c(11, 0);
    for (int i = 1; i <= 10; i++) {
      if (bit & (1 << (i - 1))) {
        for (int j = 1; j <= n; j++) {
          if (f[j][i])
            c[j]++;
        }
      }
    }
    for (int i = 1; i <= n; i++)
      subAns += (ll)p[i][c[i]];
    ans = max(ans, subAns);
  }
  cout << ans << "\n";
}

int main() {
  solve();
  return 0;
}


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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

// long C(long n, long r);
// long long gcd(long long a, long long b);
// long long lcm(long long a, long long b);

void solve() {
  int n;
  cin >> n;
  bool f[n + 1][11];
  int p[n + 1][11];

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++)
      f[i][j] = false;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 10; j++) {
      int _f;
      cin >> _f;
      if (_f == 1)
        f[i][j] = true;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 10; j++)
      cin >> p[i][j];
  }

  ll ans = LLONG_MIN;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ll subAns = 0ll;
    vector<int> c(n + 1, 0);
    for (int i = 1; i <= 10; i++) {
      if (bit & (1 << (i - 1))) {
        for (int j = 1; j <= n; j++) {
          if (f[j][i])
            c[j]++;
        }
      }
    }
    for (int i = 1; i <= n; i++)
      subAns += (ll)p[i][c[i]];
    ans = max(ans, subAns);
  }
  cout << ans << "\n";
}

int main() {
  solve();
  return 0;
}
Problem p03503 (C++)

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int M = 10;
int N;
int F[111];
int P[11][11];
signed main() {
  cin >> N;
  rep(i, N) {
    rep(j, M) {
      int a;
      cin >> a;
      F[i] = F[i] * 2 + a;
    }
  }
  rep(i, N) rep(j, M + 1) cin >> P[i][j];

  int ans = LLONG_MIN;
  for (int i = 1; i < 1 << M; i++) {
    int sum = 0;
    rep(j, N) {
      int tmp = i & F[j];
      sum += P[j][__builtin_popcount(tmp)];
    }
    chmax(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;

template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int M = 10;
int N;
int F[111];
int P[111][11];
signed main() {
  cin >> N;
  rep(i, N) {
    rep(j, M) {
      int a;
      cin >> a;
      F[i] = F[i] * 2 + a;
    }
  }
  rep(i, N) rep(j, M + 1) cin >> P[i][j];

  int ans = LLONG_MIN;
  for (int i = 1; i < 1 << M; i++) {
    int sum = 0;
    rep(j, N) {
      int tmp = i & F[j];
      sum += P[j][__builtin_popcount(tmp)];
    }
    chmax(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int f[101][11], p[101][12], flag = 0, c[12];
int main() {
  int n, i, j, k, v, sum;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++) {
      scanf("%d", &f[i][j]);
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 11; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  for (i = 1; i < 1024; i++) {
    int x = i;
    memset(c, 0, sizeof c);
    for (k = 0; k < 10; k++) {
      for (j = 0; j < n; j++) {
        if (f[j][k]) {
          if ((x >> k) & 1)
            c[j]++;
        }
      }
    }
    sum = 0;
    for (j = 0; j < n; j++) {
      sum += p[j][c[j]];
    }
    if (!flag) {
      flag = 1;
      v = sum;
    }
    if (sum > v)
      v = sum;
  }
  printf("%d\n", v);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int f[101][11], p[101][12], flag = 0, c[110];
int main() {
  int n, i, j, k, v, sum;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++) {
      scanf("%d", &f[i][j]);
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < 11; j++) {
      scanf("%d", &p[i][j]);
    }
  }
  for (i = 1; i < 1024; i++) {
    int x = i;
    memset(c, 0, sizeof c);
    for (k = 0; k < 10; k++) {
      for (j = 0; j < n; j++) {
        if (f[j][k]) {
          if ((x >> k) & 1)
            c[j]++;
        }
      }
    }
    sum = 0;
    for (j = 0; j < n; j++) {
      sum += p[j][c[j]];
    }
    if (!flag) {
      flag = 1;
      v = sum;
    }
    if (sum > v)
      v = sum;
  }
  printf("%d\n", v);
}
Problem p03503 (C++)

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
  int n;
  cin >> n;
  V<V<int>> f(n, V<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  V<V<int>> c(n, V<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> c[i][j];
    }
  }

  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      ll cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (bit & (f[i][j] << j)) {
          cnt++;
        }
      }
      sum += c[i][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
  int n;
  cin >> n;
  V<V<int>> f(n, V<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  V<V<int>> c(n, V<int>(11));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> c[i][j];
    }
  }

  ll ans = -INF;
  for (int bit = 1; bit < (1 << 10); bit++) {
    ll sum = 0;
    for (int i = 0; i < n; i++) {
      ll cnt = 0;
      for (int j = 0; j < 10; j++) {
        if (bit & (f[i][j] << j)) {
          cnt++;
        }
      }
      sum += c[i][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
  ll N;
  cin >> N;
  ll f[N + 5][10][5];
  ll p[N + 5][15];
  ll i, j, k;

  for (i = 0; i < N; i++) {
    for (j = 0; j < 5; j++) {
      cin >> f[i][j][0] >> f[i][j][1];
    }
  }

  for (i = 0; i < N; i++) {
    for (j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }

  ll ans = -INF;
  for (i = 1; i < 1 << 10; i++) {
    ll t = 0;
    ll c[11] = {};
    for (j = 0; j < 10; j++) {
      if (i >> j & 1) {
        for (k = 0; k < N; k++) {
          if (f[k][j % 5][j / 5]) {
            c[k]++;
          }
        }
      }
    }

    for (j = 0; j < N; j++)
      t += p[j][c[j]];

    chmax(ans, t);
  }

  pt(ans);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mkp(a, b) make_pair(a, b)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chmax(a, b) (a < b ? a = b : 0)
#define chmin(a, b) (a > b ? a = b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
  ll N;
  cin >> N;
  ll f[N + 5][10][5];
  ll p[N + 5][15];
  ll i, j, k;

  for (i = 0; i < N; i++) {
    for (j = 0; j < 5; j++) {
      cin >> f[i][j][0] >> f[i][j][1];
    }
  }

  for (i = 0; i < N; i++) {
    for (j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }

  ll ans = -INF;
  for (i = 1; i < 1 << 10; i++) {
    ll t = 0;
    ll c[N + 5];
    memset(c, 0, sizeof(c));
    for (j = 0; j < 10; j++) {
      if (i >> j & 1) {
        for (k = 0; k < N; k++) {
          if (f[k][j % 5][j / 5]) {
            c[k]++;
          }
        }
      }
    }

    for (j = 0; j < N; j++)
      t += p[j][c[j]];

    chmax(ans, t);
  }

  pt(ans);
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
using namespace std;
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> F(n, vector<int>(10, 0));
  // vector<vector<vector<int>>> F(n,vector<vector<int>>(5,vector<int>(2,0)));
  rep(i, n) rep(j, 10) cin >> F.at(i).at(j);
  vector<vector<int>> P(n, vector<int>(11));
  rep(i, n) rep(j, 11) cin >> P.at(i).at(j);

  ll ans = 0; // 最大値を求める。
  // joshinoお姉ちゃんの見せの時間
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> num(10, 0);
    for (int i = 0; i < 10; i++) { // 10の時間
      if (bit & (1 << i)) {        // joshino open
        for (int j = 0; j < n; j++) {
          if (F.at(j).at(i))
            num.at(j)++;
        }
      }
    }
    ll tmp = 0;
    rep(i, n) { tmp += P.at(i).at(num.at(i)); }
    if (bit == 1)
      ans = tmp;
    else
      ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
using namespace std;
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> F(n, vector<int>(10, 0));
  // vector<vector<vector<int>>> F(n,vector<vector<int>>(5,vector<int>(2,0)));
  rep(i, n) rep(j, 10) cin >> F.at(i).at(j);
  vector<vector<int>> P(n, vector<int>(11));
  rep(i, n) rep(j, 11) cin >> P.at(i).at(j);

  ll ans = 0; // 最大値を求める。
  // joshinoお姉ちゃんの見せの時間
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> num(100, 0);
    for (int i = 0; i < 10; i++) { // 10の時間
      if (bit & (1 << i)) {        // joshino open
        for (int j = 0; j < n; j++) {
          if (F.at(j).at(i))
            num.at(j)++;
        }
      }
    }
    ll tmp = 0;
    rep(i, n) { tmp += P.at(i).at(num.at(i)); }
    if (bit == 1)
      ans = tmp;
    else
      ans = max(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

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

#include <math.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

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

  int N;
  cin >> N;
  vector<int> F(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      int c;
      cin >> c;
      F[i] += (c << (9 - j));
    }
  }

  vector<vector<int>> P(N, vector<int>(10, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++)
      cin >> P[i][j];
  }

  int ans = -1e9;
  for (int i = 1; i < (1 << 10); i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++)
        if ((i >> k) & 1 && (F[j] >> k) & 1)
          cnt++;
      sum += P[j][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}


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

#include <math.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

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

  int N;
  cin >> N;
  vector<int> F(N, 0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      int c;
      cin >> c;
      F[i] += (c << (9 - j));
    }
  }

  vector<vector<int>> P(N, vector<int>(11, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++)
      cin >> P[i][j];
  }

  int ans = -1e9;
  for (int i = 1; i < (1 << 10); i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++)
        if ((i >> k) & 1 && (F[j] >> k) & 1)
          cnt++;
      sum += P[j][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}
Problem p03503 (C++)

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

int main(void) {
  int N;
  cin >> N;
  vector<vector<int>> f(N, vector<int>(10));
  vector<vector<int>> p(N, vector<int>(10));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  long long ret = -1e18;
  for (int i = 0; i < (1 << 10); i++) {
    if (__builtin_popcount(i) == 0)
      continue;
    vector<int> c(N);
    for (int j = 0; j < 10; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < N; k++) {
          if (f[k][j])
            c[k]++;
        }
      }
    }
    long long sum = 0;
    for (int j = 0; j < N; j++) {
      sum += p[j][c[j]];
    }
    ret = max(ret, sum);
  }
  cout << ret << endl;
  return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<vector<int>> f(N, vector<int>(10));
  vector<vector<int>> p(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> f[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> p[i][j];
    }
  }

  long long ret = -1e18;
  for (int i = 0; i < (1 << 10); i++) {
    if (__builtin_popcount(i) == 0)
      continue;
    vector<int> c(N);
    for (int j = 0; j < 10; j++) {
      if ((i >> j) & 1) {
        for (int k = 0; k < N; k++) {
          if (f[k][j])
            c[k]++;
        }
      }
    }
    long long sum = 0;
    for (int j = 0; j < N; j++) {
      sum += p[j][c[j]];
    }
    ret = max(ret, sum);
  }
  cout << ret << endl;
  return 0;
}
Problem p03503 (C++)

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

long long MOD = 1e9 + 7;
int MAX_INT = 1e9;
int MIN_INT = -1e9;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(5 * 2)), P(N, vector<int>(5 * 2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  int res = MIN_INT;

  for (int open = 1; open < (1 << 10); open++) {
    int cc = 0;
    for (int i = 0; i < N; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        if ((open >> j & 1) && F[i][j]) {
          c++;
        }
      }
      cc += P[i][c];
    }
    if (res < cc) {
      res = cc;
    }
  }

  cout << res << endl;

  return 0;
}


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

long long MOD = 1e9 + 7;
int MAX_INT = 1e9;
int MIN_INT = -1e9;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int N;
  cin >> N;
  vector<vector<int>> F(N, vector<int>(5 * 2)), P(N, vector<int>(11));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }
  int res = MIN_INT;

  for (int open = 1; open < (1 << 10); open++) {
    int cc = 0;
    for (int i = 0; i < N; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        if ((open >> j & 1) && F[i][j]) {
          c++;
        }
      }
      cc += P[i][c];
    }
    if (res < cc) {
      res = cc;
    }
  }

  cout << res << endl;

  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  int n;
  cin >> n;
  VVI f(n, VI(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  }
  VVI p(10, VI(11));
  for (int i = 0; i < n; i++) {
    for (int c = 0; c <= 10; c++)
      cin >> p[i][c];
  }
  int ans = -1000000000;
  for (int x = 1; x < 1024; x++) {
    int price = 0;
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        int y = f[i][j];
        if (x & y << j)
          c++;
      }
      price += p[i][c];
    }
    ans = max(ans, price);
  }
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
  int n;
  cin >> n;
  VVI f(n, VI(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  }
  VVI p(n, VI(11));
  for (int i = 0; i < n; i++) {
    for (int c = 0; c <= 10; c++)
      cin >> p[i][c];
  }
  int ans = -1000000000;
  for (int x = 1; x < 1024; x++) {
    int price = 0;
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++) {
        int y = f[i][j];
        if (x & y << j)
          c++;
      }
      price += p[i][c];
    }
    ans = max(ans, price);
  }
  cout << ans << endl;
}
Problem p03503 (C++)

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

int main() {
  int n, m;
  cin >> n;

  vector<vector<int>> f(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  }

  vector<vector<int>> p(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  }

  int ans = -2000000000;
  for (int i = 1; i < (1 << 10); i++) {
    int tmp = 0;
    bitset<10> x(i);
    for (int j = 0; j < n; j++) {
      bitset<10> fb(0);
      for (int k = 0; k < 10; k++) {
        if (f[j][k])
          fb.set(k);
      }
      fb &= x;
      tmp += p[j][fb.count()];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n;

  vector<vector<int>> f(n, vector<int>(10));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  }

  vector<vector<int>> p(n, vector<int>(11));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  }

  int ans = -2000000000;
  for (int i = 1; i < (1 << 10); i++) {
    int tmp = 0;
    bitset<10> x(i);
    for (int j = 0; j < n; j++) {
      bitset<10> fb(0);
      for (int k = 0; k < 10; k++) {
        if (f[j][k])
          fb.set(k);
      }
      fb &= x;
      tmp += p[j][fb.count()];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 105;
int f[N][20], p[N][20], n, ans = -2e9;
void dfs(string s) {
  if (s.size() == 10 && s != "0000000000") {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int num = 0;
      for (int j = 0; j < 10; j++)
        if (f[i][j] && s[j] == '1')
          num++;
      sum += p[i][num];
    }
    ans = max(ans, sum);
    return;
  }
  dfs(s + "0");
  dfs(s + "1");
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  dfs("");
  cout << ans << endl;
  return 0;
}
/*
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
*/

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 105;
int f[N][20], p[N][20], n, ans = -2e9;
void dfs(string s) {
  if (s.size() == 10) {
    if (s == "0000000000")
      return;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int num = 0;
      for (int j = 0; j < 10; j++)
        if (f[i][j] && s[j] == '1')
          num++;
      sum += p[i][num];
    }
    ans = max(ans, sum);
    return;
  }
  dfs(s + "0");
  dfs(s + "1");
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 10; j++)
      cin >> f[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 11; j++)
      cin >> p[i][j];
  dfs("");
  cout << ans << endl;
  return 0;
}
/*
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2
*/
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int32 i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int32 i = (b)-1; i >= (a); --i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int32 n;
  cin >> n;
  int32 f[100][10];
  rep(i, 0, n) {
    rep(j, 0, 10) { cin >> f[i][j]; }
  }
  int32 p[100][11];
  rep(i, 0, n) {
    rep(j, 0, 11) { cin >> p[i][j]; }
  }
  uint32 i;
  int64 ans = -1e18;
  int64 cur;
  for (i = 1; i < 1024; ++i) {
    cur = 0;
    int32 temp = 0;
    rep(j, 0, n) {
      rep(k, 0, 10) {
        if (bitget(i, k) && f[j][k]) {
          ++temp;
        }
      }
      cur += p[j][temp];
    }
    ans = max(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int32 i = (a); i < (b); ++i)
#define rrep(i, a, b) for (int32 i = (b)-1; i >= (a); --i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(), (x).end()
#define C(x) cout << #x << " : " << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int32 n;
  cin >> n;
  int32 f[100][10];
  rep(i, 0, n) {
    rep(j, 0, 10) { cin >> f[i][j]; }
  }
  int32 p[100][11];
  rep(i, 0, n) {
    rep(j, 0, 11) { cin >> p[i][j]; }
  }
  uint32 i;
  int64 ans = -1e18;
  int64 cur;
  for (i = 1; i < 1024; ++i) {
    cur = 0;
    int32 temp = 0;
    rep(j, 0, n) {
      rep(k, 0, 10) {
        if (bitget(i, k) && f[j][k]) {
          ++temp;
        }
      }
      cur += p[j][temp];
      temp = 0;
    }
    ans = max(ans, cur);
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<vector<vector<int>>> F(n, vector<vector<int>>(5, vector<int>(2)));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  vector<vector<int>> P(n, vector<int>(10, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }

  long long maxProfit = -1000000000000000;

  // i個目のbit : i / 2曜日のi % 2時間に営業するかどうか
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> c(n, 0);
    for (int i = 0; i < 10; i++) {
      if (bit & (1 << i)) {
        int yobi = i / 2;
        int zikan = i % 2;
        for (int k = 0; k < n; k++) {
          if (F[k][yobi][zikan] == 1) {
            c[k]++;
          }
        }
      }
    }
    // 利益計算
    long long profit = 0;
    for (int k = 0; k < n; k++) {
      profit += P[k][c[k]];
    }
    maxProfit = max(profit, maxProfit);
  }

  cout << maxProfit << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<vector<vector<int>>> F(n, vector<vector<int>>(5, vector<int>(2)));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      for (int k = 0; k < 2; k++) {
        cin >> F[i][j][k];
      }
    }
  }
  vector<vector<int>> P(n, vector<int>(11, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 11; j++) {
      cin >> P[i][j];
    }
  }

  long long maxProfit = -1000000000000000;

  // i個目のbit : i / 2曜日のi % 2時間に営業するかどうか
  for (int bit = 1; bit < (1 << 10); bit++) {
    vector<int> c(n, 0);
    for (int i = 0; i < 10; i++) {
      if (bit & (1 << i)) {
        int yobi = i / 2;
        int zikan = i % 2;
        for (int k = 0; k < n; k++) {
          if (F[k][yobi][zikan] == 1) {
            c[k]++;
          }
        }
      }
    }
    // 利益計算
    long long profit = 0;
    for (int k = 0; k < n; k++) {
      profit += P[k][c[k]];
    }
    maxProfit = max(profit, maxProfit);
  }

  cout << maxProfit << endl;

  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod = 1000000007;

int main() {
  LL n, f[111][12] = {}, p[111][12] = {}, ans;
  cin >> n;
  FOR(i, 0, n) FOR(j, 0, 10) cin >> f[i][j];
  FOR(i, 0, n) FOR(j, 0, 11) cin >> p[i][j];
  FOR(pat, 1, ((1 << 10) - 1)) {
    int c[12] = {};
    FOR(t, 0, 10) {
      if (!(pat & (1 << t)))
        continue;
      FOR(i, 0, n) c[i] += f[i][t];
    }
    LL sc = 0;
    FOR(i, 0, n) { sc += 1LL * p[i][c[i]]; }
    if (pat == 1) {
      ans = sc;
    } else {
      if (ans < sc)
        ans = sc;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset> //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip> //do setprecision
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod = 1000000007;

int main() {
  LL n, f[111][12] = {}, p[111][12] = {}, ans;
  cin >> n;
  FOR(i, 0, n) FOR(j, 0, 10) cin >> f[i][j];
  FOR(i, 0, n) FOR(j, 0, 11) cin >> p[i][j];
  FOR(pat, 1, ((1 << 10))) {
    int c[111] = {};
    FOR(t, 0, 10) {
      if (!(pat & (1 << t)))
        continue;
      FOR(i, 0, n) c[i] += f[i][t];
    }
    LL sc = 0;
    FOR(i, 0, n) { sc += 1LL * p[i][c[i]]; }
    if (pat == 1) {
      ans = sc;
    } else {
      if (ans < sc)
        ans = sc;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <type_traits>
#include <vector>

using namespace std;

int bitCount(int i) {
  int ret = 0;
  while (i != 0) {
    if (i % 2 == 1) {
      ret++;
    }
    i /= 2;
  }
  return ret;
}

int main(int argc, const char *argv[]) {
  long n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10, 0));
  vector<int> fb(n, 0);
  vector<vector<int>> p(n, vector<int>(10, 0));
  int tmp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> tmp;
      fb[i] += pow(2, 9 - j) * tmp;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  long long m = -99999999999;
  for (int i = 1; i < (1 << 10); i++) {
    long long sum = 0;
    for (int j = 0; j < n; j++) {
      sum += p[j][bitCount(i & fb[j])];
      ;
    }
    m = max(m, sum);
  }

  cout << m << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <type_traits>
#include <vector>

using namespace std;

int bitCount(int i) {
  int ret = 0;
  while (i != 0) {
    if (i % 2 == 1) {
      ret++;
    }
    i /= 2;
  }
  return ret;
}

int main(int argc, const char *argv[]) {
  long n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10, 0));
  vector<int> fb(n, 0);
  vector<vector<int>> p(n, vector<int>(11, 0));
  int tmp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> tmp;
      fb[i] += pow(2, 9 - j) * tmp;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 10; j++) {
      cin >> p[i][j];
    }
  }
  long long m = -99999999999;
  for (int i = 1; i < (1 << 10); i++) {
    long long sum = 0;
    for (int j = 0; j < n; j++) {
      sum += p[j][bitCount(i & fb[j])];
      ;
    }
    m = max(m, sum);
  }

  cout << m << endl;
  return 0;
}
Problem p03503 (C++)

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

const int INF = numeric_limits<int>::max();

int main() {
  int n;
  cin >> n;
  vector<vector<int>> F(n, vector<int>(10));
  vector<vector<int>> P(n, vector<int>(10));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }

  int ans = -INF;
  for (int i = 1; i < 1024; ++i) {
    int res = 0;
    for (int j = 0; j < n; ++j) {
      int c = 0;
      for (int k = 0; k < 10; ++k) {
        if (F[j][k] and (i & (1 << k)))
          ++c;
      }
      res += P[j][c];
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}


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

const int INF = numeric_limits<int>::max();

int main() {
  int n;
  cin >> n;
  vector<vector<int>> F(n, vector<int>(10));
  vector<vector<int>> P(n, vector<int>(11));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> F[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 11; ++j) {
      cin >> P[i][j];
    }
  }

  int ans = -INF;
  for (int i = 1; i < 1024; ++i) {
    int res = 0;
    for (int j = 0; j < n; ++j) {
      int c = 0;
      for (int k = 0; k < 10; ++k) {
        if (F[j][k] and (i & (1 << k)))
          ++c;
      }
      res += P[j][c];
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
}
Problem p03503 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define repeq(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// C - Shopping Street
int N;
int F[100][10];
int P[100][10];
int sum[100];
int ans = -2000000000;

int main() {
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) { cin >> F[i][j]; }
  }
  rep(i, 0, N) {
    rep(j, 0, 11) { cin >> P[i][j]; }
  }
  int L = 10;
  // 2^L - 1回の全探索
  for (int i = 0; i < 1 << L; ++i) {
    if (i == 0)
      continue;
    int r;
    rep(j, 0, N) { sum[j] = 0; }
    for (r = 0; r < L; ++r) {
      // Bitが立っているときの処理
      if ((i & (1 << r)) != 0) {
        rep(j, 0, N) { sum[j] += F[j][r]; }
      }
    }
    int tmp = 0;
    rep(j, 0, N) { tmp += P[j][sum[j]]; }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define repeq(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// C - Shopping Street
int N;
int F[100][10];
int P[100][11];
int sum[100];
int ans = -2000000000;

int main() {
  cin >> N;
  rep(i, 0, N) {
    rep(j, 0, 10) { cin >> F[i][j]; }
  }
  rep(i, 0, N) {
    rep(j, 0, 11) { cin >> P[i][j]; }
  }
  int L = 10;
  // 2^L - 1回の全探索
  for (int i = 0; i < 1 << L; ++i) {
    if (i == 0)
      continue;
    int r;
    rep(j, 0, N) { sum[j] = 0; }
    for (r = 0; r < L; ++r) {
      // Bitが立っているときの処理
      if ((i & (1 << r)) != 0) {
        rep(j, 0, N) { sum[j] += F[j][r]; }
      }
    }
    int tmp = 0;
    rep(j, 0, N) { tmp += P[j][sum[j]]; }
    ans = max(ans, tmp);
  }

  cout << ans << endl;
  return 0;
}
Problem p03503 (Python)

Buggy submission (status: Runtime Error):
import math

N = int(input())
F = [[] * 10 for i in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] * 11 for i in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))
L = [0] * 10
Sum_max = -float(math.inf)
for i in range(1, 1024):
    for j in range(10):
        L[j] = i % 2
        i = int(i / 2)
    Sum = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if L[k] == 1 and F[j][k] == 1:
                count += 1
        Sum += P[j][count]
    Sum_max = max(Sum_max, Sum)
print(Sum_max)


Fixed submission:
import math

N = int(input())
F = [[] * 10 for i in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] * 11 for i in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))
L = [0] * 10
Sum_max = -float("inf")
for i in range(1, 1024):
    for j in range(10):
        L[j] = i % 2
        i = int(i / 2)
    Sum = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if L[k] == 1 and F[j][k] == 1:
                count += 1
        Sum += P[j][count]
    Sum_max = max(Sum_max, Sum)
print(Sum_max)
Problem p03503 (C++)

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

int main() {
  int N, F[10][100], P[11][100];
  cin >> N;
  for (int j(0); j < N; j++) {
    for (int i(0); i < 10; i++) {
      cin >> F[j][i];
    }
  }
  for (int j(0); j < N; j++) {
    for (int i(0); i < 11; i++) {
      cin >> P[j][i];
    }
  }
  ll ans(-1000000000000);
  for (int bit = 1; bit < (1 << 10); ++bit) {
    ll benefit(0);
    ll kosuu[100] = {0};
    for (int i = 0; i < 10; ++i) {
      if (bit & (1 << i)) { // i が bit に入るかどうか
        for (int n(0); n < N; n++) {
          if (F[n][i] == 1)
            kosuu[n] += 1;
        }
      }
    }
    for (int n(0); n < N; n++) {
      // cout << kosuu[n]<<" "<<P[n][kosuu[n]]<<" ";
      benefit += P[n][kosuu[n]];
    }
    // cout << endl;
    // cout << benefit << " ";
    ans = max(benefit, ans);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, F[100][10], P[100][11];
  cin >> N;
  for (int j(0); j < N; j++) {
    for (int i(0); i < 10; i++) {
      cin >> F[j][i];
    }
  }
  for (int j(0); j < N; j++) {
    for (int i(0); i < 11; i++) {
      cin >> P[j][i];
    }
  }
  ll ans(-1000000000000);
  for (int bit = 1; bit < (1 << 10); ++bit) {
    ll benefit(0);
    ll kosuu[100] = {0};
    for (int i = 0; i < 10; ++i) {
      if (bit & (1 << i)) { // i が bit に入るかどうか
        for (int n(0); n < N; n++) {
          if (F[n][i] == 1)
            kosuu[n] += 1;
        }
      }
    }
    for (int n(0); n < N; n++) {
      // cout << kosuu[n]<<" "<<P[n][kosuu[n]]<<" ";
      benefit += P[n][kosuu[n]];
    }
    // cout << endl;
    // cout << benefit << " ";
    ans = max(benefit, ans);
  }
  cout << ans << endl;
  return 0;
}