alexjercan/bugnet huggingface dataset:
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  bool osenbei[15][15000][2];
  int h, w, a, b, c, sum, MAXN, ura[10];
  int osenbei2;
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) {
      break;
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> osenbei2;
        if (osenbei2 == 1) {
          osenbei[i][j][0] = true;
          osenbei[i][j][1] = true;
        } else {
          osenbei[i][j][0] = false;
          osenbei[i][j][1] = false;
        }
      }
    }
    a = 1;
    for (int k = 0; k < h; k++) {
      a *= 2;
    }
    MAXN = 0;
    for (int i = 0; i < a; i++) {
      sum = 0;
      for (int j = 0; j < h; j++) {
        b = 1;
        for (int k = 0; k < j; k++) {
          b *= 2;
        }
        ura[j] = (i / b) % 2;
        if (ura[j] == 1) {
          for (int k = 0; k < w; k++) {
            if (osenbei[j][k][1] == false) {
              osenbei[j][k][1] = true;
            } else {
              osenbei[j][k][1] = false;
            }
          }
        }
      }
      for (int j = 0; j < w; j++) {
        c = 0;
        for (int k = 0; k < h; k++) {
          if (osenbei[k][j][1] == false) {
            c++;
          }
        }
        sum += max(h - c, c);
      }
      MAXN = max(sum, MAXN);
      for (int j = 0; j < h; j++) {
        for (int k = 0; k < w; k++) {
          osenbei[j][k][1] = osenbei[j][k][0];
        }
      }
    }
    cout << MAXN << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  bool osenbei[10][10000][2];
  int h, w, a, b, c, sum, MAX, ura[10];
  int osenbei2;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> osenbei2;
      if (osenbei2 == 1) {
        osenbei[i][j][0] = true;
        osenbei[i][j][1] = true;
      } else {
        osenbei[i][j][0] = false;
        osenbei[i][j][1] = false;
      }
    }
  }
  a = 1;
  for (int k = 0; k < h; k++) {
    a *= 2;
  }
  MAX = 0;
  for (int i = 0; i < a; i++) {
    sum = 0;
    for (int j = 0; j < h; j++) {
      b = 1;
      for (int k = 0; k < j; k++) {
        b *= 2;
      }
      ura[j] = (i / b) % 2;
      if (ura[j] == 1) {
        for (int k = 0; k < w; k++) {
          if (osenbei[j][k][1] == false) {
            osenbei[j][k][1] = true;
          } else {
            osenbei[j][k][1] = false;
          }
        }
      }
    }
    for (int j = 0; j < w; j++) {
      c = 0;
      for (int k = 0; k < h; k++) {
        if (osenbei[k][j][1] == false) {
          c++;
        }
      }
      if (h - c > c) {
        sum += h - c;
      } else {
        sum += c;
      }
    }
    MAX = max(sum, MAX);
    for (int j = 0; j < h; j++) {
      for (int k = 0; k < h; k++) {
        osenbei[i][j][1] = osenbei[i][j][0];
      }
    }
  }
  cout << MAX << endl;
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
// #define int long long
using namespace std;
typedef long long ll;

int R, C;
int a[10][10000];

signed main() {
  while (true) {
    cin >> R >> C;
    if (R == 0 && C == 0)
      break;
    // rep(i,R) rep(j,C) cin >> a[i][j];
    rep(i, R) rep(j, C) scanf("%d", &a[i][j]);

    int ans = 0;
    for (int i = 0; i < 1 << R; i++) {
      int temp = 0;
      rep(j, C) {
        int one = 0;
        rep(k, R) {
          if ((i >> k & 1) && (a[k][j] == 0))
            one++;
          else if (!(i >> k & 1) && (a[k][j] == 1))
            one++;
        }
        temp += max(one, R - one);
      }
      ans = max(ans, temp);
    }

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
// #define int long long
using namespace std;
typedef long long ll;

int R, C;
int a[10][10000];

signed main() {
  while (true) {
    cin >> R >> C;
    // rep(i,R) rep(j,C) cin >> a[i][j];
    rep(i, R) rep(j, C) scanf("%d", &a[i][j]);

    int ans = 0;
    for (int i = 0; i < 1 << R; i++) {
      int temp = 0;
      rep(j, C) {
        int one = 0;
        rep(k, R) {
          if ((i >> k & 1) && (a[k][j] == 0))
            one++;
          else if (!(i >> k & 1) && (a[k][j] == 1))
            one++;
        }
        temp += max(one, R - one);
      }
      ans = max(ans, temp);
    }

    cout << ans << endl;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

constexpr int MAX_C = 10;
constexpr int MAX_R = 10000;

int R, C;
bool a[MAX_C][MAX_R];

int solve();

int dfs(const int &n = 0);

int main() {
  std::ios::sync_with_stdio(false);
  while (true) {
    std::cin >> C >> R;

    if (C == 0 && R == 0) {
      break;
    }

    for (int i = 0; i < C; ++i) {
      for (int j = 0; j < R; ++j) {
        char in;
        std::cin >> in;
        if (in == '1') {
          a[i][j] = true;
        } else {
          a[i][j] = false;
        }
      }
    }

    std::cout << dfs() << std::endl;
  }
  return 0;
}

int dfs(const int &n) {
  if (n == C) {
    return solve();
  }

  int res = 0;
  for (int i = 0; i < R; ++i) {
    a[n][i] = !a[n][i];
  }
  res = dfs(n + 1);
  for (int i = 0; i < R; ++i) {
    a[n][i] = !a[n][i];
  }
  res = std::max(res, dfs(n + 1));

  return res;
}

int solve() {
  int res = 0;
  for (int i = 0; i < R; ++i) {
    int _a = 0, _b = 0;
    for (int j = 0; j < C; ++j) {
      if (a[j][i]) {
        ++_a;
      } else {
        ++_b;
      }
    }
    res += std::max(_a, _b);
  }
  return res;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

constexpr int MAX_C = 10;
constexpr int MAX_R = 10000;

int R, C;
bool a[1 << (MAX_C + 1)][MAX_R][MAX_C];

int solve(const int &N);

int main() {
  std::ios::sync_with_stdio(false);
  while (true) {
    std::cin >> C >> R;

    if (C == 0 && R == 0) {
      break;
    }

    for (int i = 0; i < C; ++i) {
      for (int j = 0; j < R; ++j) {
        int in;
        std::cin >> in;

        for (int k = 0; k < 1 << (C + 1); ++k) {
          if (i & 1 << k) {
            if (!in) {
              a[k][i][j] = true;
            } else {
              a[k][i][j] = false;
            }
          } else {
            if (in) {
              a[k][i][j] = true;
            } else {
              a[k][i][j] = false;
            }
          }
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < 1 << (C + 1); ++i) {
      ans = std::max(ans, solve(i));
      // std::cout << "i : " << i << " ans : " << ans << std::endl;
    }

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

int solve(const int &N) {
  int res = 0;
  for (int i = 0; i < R; ++i) {
    int _a = 0, _b = 0;
    for (int j = 0; j < C; ++j) {
      if (a[N][j][i]) {
        ++_a;
      } else {
        ++_b;
      }
    }
    res += std::max(_a, _b);
  }
  return res;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)

int R, C;         // 行、列
int s[10][10000]; // せんべい
int s2[10][10000];
bool g[10][2047]; // 組み合わせ

// 組み合わせの生成
void gen(int n, int x) { // 上からn+1列目、配列の格納番号
  if (n == R)
    return;

  REP(i, n) {
    g[i][x * 2 - 2] = g[i][x - 2];
    g[i][x * 2 - 1] = g[i][x - 2];
  }

  g[n][x * 2 - 2] = true;
  gen(n + 1, x * 2);
  g[n][x * 2 - 1] = false;
  gen(n + 1, x * 2 + 1);
  return;
}

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

  while (1) {
    int tori = 1; // 2^R
    int ans = 0;  // 答え

    cin >> R >> C;
    if (R == 0 && C == 0)
      break;

    REP(i, R) tori *= 2; // tori = 2^R

    // 組み合わせを生成
    gen(0, 1);

    REP(i, R) {
      REP(j, C) {
        cin >> s[i][j];
        s2[i][j] = s[i][j];
      }
    }

    REP(i, tori) {
      // その列の組み合わせでの最大個数
      int ma = 0;

      // 行の反転
      REP(j, R) {
        if (g[j][i + tori - 2]) {
          REP(k, C)(s[j][k] == 0) ? s[j][k] = 1 : s[j][k] = 0;
        }
      }

      // 全ての列について、多いほうをとる
      REP(j, C) {
        int O = 0, U = 0; // 表の枚数、裏の枚数
        REP(k, R)(s[k][j] == 0) ? O++ : U++;
        ma += max(O, U);
      }

      if (ma > ans)
        ans = ma;

      REP(j, R) {
        REP(k, C) { s[j][k] = s2[j][k]; }
      }
    }

    cout << ans << "\\n";
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)

int R, C;         // 行、列
int s[10][10000]; // せんべい
int tori = 1;     // 2^R
int ans = 0;      // 答え
bool g[10][2047]; // 組み合わせ

// 組み合わせの生成
void gen(int n, int x) { // 上からn+1列目、配列の格納番号
  if (n == R)
    return;

  REP(i, n) {
    g[i][x * 2 - 2] = g[i][x - 2];
    g[i][x * 2 - 1] = g[i][x - 2];
  }

  g[n][x * 2 - 2] = true;
  gen(n + 1, x * 2);
  g[n][x * 2 - 1] = false;
  gen(n + 1, x * 2 + 1);
  return;
}

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

  while (1) {
    cin >> R >> C;
    if (R == 0 && C == 0)
      break;

    REP(i, R) tori *= 2;

    // 組み合わせを生成
    gen(0, 1);

    REP(i, R) { REP(j, C) cin >> s[i][j]; }

    REP(i, tori) {
      // その列の組み合わせでの最大個数
      int ma = 0;

      // 行の反転
      REP(j, R) {
        if (g[j][i + tori - 2]) {
          REP(k, C)(s[j][k] == 0) ? s[j][k] = 1 : s[j][k] = 0;
        }
      }

      // 全ての列について、多いほうをとる
      REP(j, C) {
        int O = 0, U = 0; // 表の枚数、裏の枚数
        REP(k, R)(s[k][j] == 0) ? O++ : U++;
        ma += max(O, U);
      }

      if (ma > ans)
        ans = ma;
    }

    cout << ans << "\\n";
  }

  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

#define MAX_R 10
#define MAX_C 10000
#define rep(a) for (int i = 0, i < (a), ++i)

int R, C, ans;
int field[MAX_R][MAX_C];
bool flag[MAX_R] = {false};

void solve(int n);

int count();

int main() {
  while (true) {
    std::cin >> R >> C;
    if (R == 0 && C == 0)
      break;
    for (int i = 0; i < R; ++i) {
      for (int j = 0; j < C; ++j) {
        std::cin >> field[i][j];
      }
    }
    ans = 0;
    solve(0);
    std::cout << ans << std::endl;
  }
  return 0;
}

void solve(int n) {
  if (n == R) {
    ans = std::max(ans, count());
    return;
  }

  flag[n] = true;
  solve(n + 1);

  flag[n] = false;
  solve(n + 1);

  return;
}

int count() {
  int res = 0;

  for (int i = 0; i < C; ++i) {
    int tmp = 0;
    for (int j = 0; j < R; ++j) {
      if ((flag[j] && !field[j][i]) || (!flag[j] && field[j][i]))
        ++tmp;
    }
    res += std::max(tmp, R - tmp);
  }

  return res;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

#define MAX_R 10
#define MAX_C 10000

int R, C, ans;
int field[MAX_R][MAX_C];
bool flag[MAX_R] = {false};

void solve(int n);

int count();

int main() {
  while (true) {
    std::cin >> R >> C;
    for (int i = 0; i < R; ++i) {
      for (int j = 0; j < C; ++j) {
        std::cin >> field[i][j];
      }
    }
    ans = 0;
    solve(0);
    std::cout << ans << std::endl;
  }
  return 0;
}

void solve(int n) {
  if (n == R) {
    ans = std::max(ans, count());
    return;
  }

  flag[n] = true;
  solve(n + 1);

  flag[n] = false;
  solve(n + 1);

  return;
}

int count() {
  int res = 0;

  for (int i = 0; i < C; ++i) {
    int count = 0;
    for (int j = 0; j < R; ++j) {
      if (flag[j]) {
        if (field[j][i] == 0)
          ++field[j][i];
        else
          --field[j][i];
      }
      if (field[j][i] == 0)
        ++count;
    }

    res += std::max(count, R - count);
  }

  return res;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define INF 10000000
using namespace std;
typedef pair<int, int> P;

int sumRow(int n);
int sumCol(int n);
int check();
void changeRow(int n);
void changeCol(int n);

int senbei[10][10000];
int r, c;
int rowFlag[10];
int Max;

void countSum() {
  int sum = 0;
  for (int i = 0; i < c; i++) {
    int colSum = 0;
    for (int j = 0; j < r; j++) {
      if (senbei[j][i] == !rowFlag[j]) {
        colSum++;
      }
    }
    sum += max(colSum, r - colSum);
  }
  if (Max < sum) {
    Max = sum;
  }
}

void setFlag(int pos) {
  if (pos == r) {
    countSum();
    return;
  }
  rowFlag[pos] = 1;
  setFlag(pos + 1);

  rowFlag[pos] = 0;
  setFlag(pos + 1);
}

int main() {
  while (1) {
    cin >> r >> c;
    if (r == 0 && c == 0)
      return 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> senbei[i][j];
      }
    }
    Max = 0;
    setFlag(0);
    cout << Max << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define INF 10000000
using namespace std;
typedef pair<int, int> P;

int sumRow(int n);
int sumCol(int n);
int check();
void changeRow(int n);
void changeCol(int n);

int senbei[10][10000];
int r, c;

int main() {
  while (1) {
    cin >> r >> c;
    if (r == 0 && c == 0)
      return 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> senbei[i][j];
      }
    }

    int before = -1;
    while (1) {
      int max = 0;
      int isR = 1;
      int pos = -1;
      for (int i = 0; i < r; i++) {
        int temp = sumRow(i);
        if (temp > max && 2 * temp >= c && i != before) {
          max = temp;
          pos = i;
        }
      }
      for (int i = 0; i < c; i++) {
        int temp = sumCol(i);
        if (temp > max && 2 * temp >= r && i != before) {
          max = temp;
          pos = i;
          isR = 0;
        }
      }
      if (pos >= 0) {
        if (isR) {
          changeRow(pos);
        } else {
          changeCol(pos);
        }
        before = pos;
      } else {
        break;
      }
    }
    cout << check() << endl;
  }
}

int sumRow(int n) {
  int sum = 0;
  for (int i = 0; i < c; i++)
    sum += senbei[n][i];
  return sum;
}

int sumCol(int n) {
  int sum = 0;
  for (int i = 0; i < r; i++)
    sum += senbei[i][n];
  return sum;
}

int check() {
  int sum = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (!senbei[i][j]) {
        sum++;
      }
    }
  }
  return sum;
}

// 横ひっくり返し
void changeRow(int n) {
  for (int i = 0; i < c; i++) {
    senbei[n][i] = !senbei[n][i];
  }
}

// 縦
void changeCol(int n) {
  for (int i = 0; i < r; i++) {
    senbei[i][n] = !senbei[i][n];
  }
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
using namespace std;
int sen[10010][20];
int tate, yoko;
int cou(int sum[10010][2], int row) {
  if (row == tate) {
    int ans = 0;
    for (int i = 0; i < yoko; i++)
      ans = ans + max(sum[i][0], sum[i][1]);
    return ans;
  }
  int sum0[10010][2] = {0}, sum1[10010][2] = {0}, ans0, ans1;
  for (int i = 0; i < yoko; i++) {
    sum0[i][0] = sum[i][0];
    sum0[i][1] = sum[i][1];
    sum1[i][0] = sum[i][0];
    sum1[i][1] = sum[i][1];
    if (sen[i][row] == 0) {
      sum0[i][0]++;
      sum1[i][1]++;
    } else {
      sum0[i][1]++;
      sum1[i][0]++;
    }
  }
  ans0 = cou(sum0, row + 1);
  ans1 = cou(sum1, row + 1);
  return max(ans0, ans1);
}
int main() {
  while (scanf("%d%d", &tate, &yoko), tate + yoko) {
    int sam[10010][2] = {0};
    for (int i = 0; i < tate; i++)
      for (int j = 0; j < yoko; j++)
        scanf("%d", &sen[j][i]);
    printf("%d\\n", cou(sam, 0));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int sen[20][10010];
int tate, yoko;
int cou(int sum[10010][2], int row) {
  if (row == tate) {
    int ans = 0;
    for (int i = 0; i < yoko; i++)
      ans = ans + max(sum[i][0], sum[i][1]);
    return ans;
  }
  int sum0[10010][2] = {0}, sum1[10010][2] = {0}, ans0, ans1;
  for (int i = 0; i < yoko; i++) {
    sum0[i][0] = sum[i][0];
    sum0[i][1] = sum[i][1];
    sum1[i][0] = sum[i][0];
    sum1[i][1] = sum[i][1];
    if (sen[i][row] == 0) {
      sum0[i][0]++;
      sum1[i][1]++;
    } else {
      sum0[i][1]++;
      sum1[i][0]++;
    }
  }
  ans0 = cou(sum0, row + 1);
  ans1 = cou(sum1, row + 1);
  return max(ans0, ans1);
}
int main() {
  while (scanf("%d%d", &tate, &yoko), tate + yoko) {
    int sam[10010][2] = {0};
    for (int i = 0; i < tate; i++)
      for (int j = 0; j < yoko; j++)
        scanf("%d", &sen[j][i]);
    printf("%d\\n", cou(sam, 0));
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int map[11][10001];
int turn[11];
int r, c, ans;

void serch(int n) {
  int i, j;
  if (n == r) {
    int ss;
    int ssans = 0;
    for (i = 0; i < c; i++) {
      ss = 0;
      for (j = 0; j < r; j++) {
        //				cout << map[j][i] << " " ;
        if (turn[j] == 0) {
          if (map[j][i] == 1)
            ss++;
        } else if (turn[j] == 1) {
          if (map[j][i] == 0)
            ss++;
        }
      }
      //			cout << endl;
      if (ss <= r / 2) {
        //				cout << "ss1:" << r-ss << endl;
        ssans += r - ss;
      } else {
        //				cout << "ss2:" << ss << endl;
        ssans += ss;
      }
      //			cout << "ssans:" << ssans << endl;
    }
    if (ans < ssans)
      ans = ssans;
    return;
  }
  turn[n] = 0;
  serch(n + 1);
  turn[n] = 1;
  serch(n + 1);
  return;
}
int main() {
  int i, j;

  for (;;) {
    cin >> r >> c;
    if (r == 0 && c == 0)
      break;

    for (i = 0; i < r; i++) {
      for (j = 0; j < c; j++) {
        cin >> map[i][j];
      }
    }

    ans = 0;

    serch(0);

    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int map[11][10001];
int turn[11];
int r, c, ans;

void serch(int n) {
  int i, j;
  if (n == r) {
    int ss;
    int ssans = 0;
    for (i = 0; i < c; i++) {
      ss = 0;
      for (j = 0; j < r; j++) {
        //				cout << map[j][i] << " " ;
        if (turn[j] == 0) {
          if (map[j][i] == 1)
            ss++;
        } else if (turn[j] == 1) {
          if (map[j][i] == 0)
            ss++;
        }
      }
      //			cout << endl;
      if (ss <= r / 2) {
        //				cout << "ss1:" << r-ss << endl;
        ssans += r - ss;
      } else {
        //				cout << "ss2:" << ss << endl;
        ssans += ss;
      }
      //		cout << "ssans:" << ssans << endl;
    }
    if (ans < ssans)
      ans = ssans;
    return;
  }
  for (i = n; i < r; i++) {
    turn[n] = 0;
    serch(n + 1);
    turn[n] = 1;
    serch(n + 1);
  }
  return;
}
int main() {
  int i, j;

  for (;;) {
    cin >> r >> c;
    if (r == 0 && c == 0)
      break;

    for (i = 0; i < r; i++) {
      for (j = 0; j < c; j++) {
        cin >> map[i][j];
      }
    }

    ans = 0;

    serch(0);

    cout << ans << endl;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
int R, C;
const int MAX_R = 12;
const int MAX_C = 10020;
bool omote[MAX_R][MAX_C];
int avai[MAX_C];
int avai_ori[MAX_C]; // 変化させない
int main(int argc, const char *argv[]) {
  while (true) {
    scanf("%d %d", &R, &C);
    if (R == 0 && C == 0)
      break;
    int ret = 0;
    memset(avai_ori, 0, sizeof(avai_ori));
    memset(avai, 0, sizeof(avai));
    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        int n;
        scanf("%d", &n); // 表なら1,裏なら0
        omote[i][j] = n;
        if (n == 0) { // 裏の場合
          avai[j]++;
          avai_ori[j]++;
        }
      }
    }

    for (int i = 0; i < (1 << R); i++) {
      for (int j = 0; j < C; j++)
        avai[j] = avai_ori[j];
      for (int j = 0; j < R; j++) {
        if ((i >> j) & 1) { // j行目を裏返す場合
          for (int k = 0; k < C; k++) {
            if (omote[j][k])
              avai[k]++;
            else
              avai[k]--;
          }
        }
      }
      int sum = 0;
      for (int j = 0; j < C; j++) {
        sum += max(avai[j], R - avai[j]);
      }
      ret = max(ret, sum);
    }
    printf("%d\\n", ret);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
int R, C;
const int MAX_R = 12;
const int MAX_C = 10020;
bool omote[MAX_R][MAX_C];
int avai[MAX_C];
int avai_ori[MAX_C]; // 変化させない
int main(int argc, const char *argv[]) {
  while (true) {
    scanf("%d %d", &R, &C);
    if (R == 0 && C == 0)
      break;
    int ret = 0;
    memset(avai_ori, 0, sizeof(avai_ori));
    memset(avai, 0, sizeof(avai));
    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        int n;
        scanf("%d", &n); // 表なら1,裏なら0
        omote[i][j] = n;
        if (n == 0) { // 裏の場合
          avai[j]++;
          avai_ori[j]++;
        }
      }
    }

    for (int i = 0; i < (1 << R); i++) {
      for (int j = 0; j < C; j++)
        avai[j] = avai_ori[j];
      for (int j = 0; j < R; j++) {
        if ((i >> j) & 1) { // j行目を裏返す場合
          for (int k = 0; k < C; k++) {
            if (omote[i][j]) {
              if (omote[j][k])
                avai[k]++;
              else
                avai[k]--;
            }
          }
        }
      }
      int sum = 0;
      for (int j = 0; j < C; j++) {
        sum += max(avai[j], R - avai[j]);
      }
      ret = max(ret, sum);
    }
    printf("%d\\n", ret);
  }

  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>

using namespace std;

int s[10][400];
int t[10][400];
int H, W;

int main() {
  // freopen("in.txt", "r", stdin);

  while (scanf("%d%d", &H, &W) == 2) {
    if (H == 0 || W == 0)
      break;
    int i, j;

    memset(s, 0, sizeof(s));

    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        int c;
        scanf("%d", &c);
        s[i][j / 32] |= c << (j % 32);
      }
    }

    int mask;
    int limit = 1 << H;
    int max = 0;
    for (mask = 0; mask < limit; mask++) {

      for (i = 0; i < H; i++) {
        if (mask & (1 << i)) {
          for (j = 0; j < 400; j++)
            t[i][j] = s[i][j] ^ 0xffffffff;

        } else {
          for (j = 0; j < 400; j++)
            t[i][j] = s[i][j];
        }
      }

      int sum = 0;
      for (j = 0; j < W; j++) {
        int col_num = 0;
        int col, bit;
        col = j / 32;
        bit = 1 << (j % 32);
        for (i = 0; i < H; i++) {
          if (t[i][col] & bit)
            col_num++;
        }
        if (col_num < H - col_num)
          col_num = H - col_num;
        sum += col_num;
      }
      if (max < sum)
        max = sum;
    }
    printf("%d\\n", max);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>

using namespace std;

int s[10][40];
int t[10][40];
int H, W;

int main() {
  // freopen("in.txt", "r", stdin);

  while (scanf("%d%d", &H, &W) == 2) {
    if (H == 0 || W == 0)
      break;
    int i, j;

    memset(s, 0, sizeof(s));

    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        int c;
        scanf("%d", &c);
        s[i][j / 32] |= c << (j % 32);
      }
    }

    int mask;
    int limit = 1 << H;
    int max = 0;
    for (mask = 0; mask < limit; mask++) {

      for (i = 0; i < H; i++) {
        if (mask & (1 << i)) {
          for (j = 0; j < 40; j++)
            t[i][j] = s[i][j] ^ 0xffffffff;

        } else {
          for (j = 0; j < 40; j++)
            t[i][j] = s[i][j];
        }
      }

      int sum = 0;
      for (j = 0; j < W; j++) {
        int col_num = 0;
        int col, bit;
        col = j / 32;
        bit = 1 << (j % 32);
        for (i = 0; i < H; i++) {
          if (t[i][col] & bit)
            col_num++;
        }
        if (col_num < H - col_num)
          col_num = H - col_num;
        sum += col_num;
      }
      if (max < sum)
        max = sum;
    }
    printf("%d\\n", max);
  }

  return 0;
}