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

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int R, C;
const int MAX = 10000;
bool senbei[MAX][MAX];
int count() {
  /*cout << "begin" << endl;
  for(int i = 0;i < R;i++){
    for(int j = 0;j < C;j++){
      cout << (int)senbei[i][j];
    }
    cout << endl;
  }
  */

  int ans = 0;

  for (int i = 0; i < C; i++) {
    int num = 0;
    for (int j = 0; j < R; j++) {
      if (senbei[j][i])
        num++;
    }
    ans += max(num, R - num);
  }

  // cout << ans << endl;
  // cout << "end" << endl;
  return ans;
}

int dfs(int r) {
  if (r == 0)
    return count();
  int ans = dfs(r - 1);
  for (int i = 0; i < C; ++i)
    senbei[r][i] = !senbei[r][i];
  ans = max(dfs(r - 1), ans);
  for (int i = 0; i < C; ++i)
    senbei[r][i] = !senbei[r][i];
  return ans;
}
int main() {
  ios::sync_with_stdio(false);

  while (cin >> R >> C && (R + C) > 0) {
    for (int r = 0; r < R; ++r) {
      for (int c = 0; c < C; ++c) {
        bool b;
        cin >> b;
        senbei[r][c] = b > 0 ? true : false;
      }
    }
    cout << dfs(R) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int R, C;
const int MAX = 10000;
bool senbei[10][MAX];
int count() {
  /*cout << "begin" << endl;
  for(int i = 0;i < R;i++){
    for(int j = 0;j < C;j++){
      cout << (int)senbei[i][j];
    }
    cout << endl;
  }
  */

  int ans = 0;

  for (int i = 0; i < C; i++) {
    int num = 0;
    for (int j = 0; j < R; j++) {
      if (senbei[j][i])
        num++;
    }
    ans += max(num, R - num);
  }

  // cout << ans << endl;
  // cout << "end" << endl;
  return ans;
}

int dfs(int r) {
  if (r == 0)
    return count();
  int ans = dfs(r - 1);
  for (int i = 0; i < C; ++i)
    senbei[r][i] = !senbei[r][i];
  ans = max(dfs(r - 1), ans);
  for (int i = 0; i < C; ++i)
    senbei[r][i] = !senbei[r][i];
  return ans;
}
int main() {
  ios::sync_with_stdio(false);

  while (cin >> R >> C && (R + C) > 0) {
    for (int r = 0; r < R; ++r) {
      for (int c = 0; c < C; ++c) {
        bool b;
        cin >> b;
        senbei[r][c] = b > 0 ? true : false;
      }
    }
    cout << dfs(R) << endl;
  }

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

#include <stdio.h>
int r, c, s[10][10000], n;

int f(int d[10][10000], bool t[10]) {
  int max = 0, i, j, jk;
  for (i = 0; i < r; i++) {
    if (t[i]) {
      for (j = 0; j < c; j++) {
        d[i][j] = !d[i][j];
      }
    }
  }
  /*for(i=0;i<r;i++){
                  for(j=0;j<c;j++){
                          printf("%d",d[i][j]);
                  }
                  puts("");
  }*/
  for (i = 0; i < c; i++) {
    jk = 0;
    for (j = 0; j < r; j++) {
      jk += d[j][i];
    }
    if (jk > r - jk)
      max += jk;
    else
      max += r - jk;
  }
  // printf("%d\\n",max);
  for (i = 0; i < r; i++) {
    if (t[i]) {
      for (j = 0; j < c; j++) {
        d[i][j] = !d[i][j];
      }
    }
  }
  return max;
}
void search(bool turn[10], int k) {
  if (r == k) {
    int o;
    /*for(int i=0;i<r;i++){
            printf("%d",turn[i]);
    }
    puts("");*/
    o = f(s, turn);
    if (o > n)
      n = o;
  } else {
    turn[k] = true;
    search(turn, k + 1);
    turn[k] = false;
    search(turn, k + 1);
  }
}

int main() {
  int i, j;
  bool b[10];
  for (;;) {
    scanf("%d%d", &r, &c);
    if (!r && !c)
      break;
    n = 0;
    for (i = 0; i < r; i++)
      for (j = 0; j < c; j++)
        scanf("%d", &s[i][j]);
    search(b, 0);
    printf("%d\\n", n);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int r, c, s[10][10000], n;

int f(int d[10][10000], bool t[10]) {
  int max = 0, i, j, jk;
  for (i = 0; i < r; i++) {
    if (t[i]) {
      for (j = 0; j < c; j++) {
        d[i][j] = 1 - d[i][j];
      }
    }
  }
  for (i = 0; i < c; i++) {
    jk = 0;
    for (j = 0; j < r; j++) {
      jk += d[i][j];
    }
    if (jk > r - jk)
      max += jk;
    else
      max += r - jk;
  }
  printf("%d\\n", max);
  return max;
}
void search(bool turn[10], int k) {
  if (r == k) {
    int o;
    o = f(s, turn);
    if (o > n)
      n = o;
  } else {
    turn[k] = true;
    search(turn, k + 1);
    turn[k] = false;
    search(turn, k + 1);
  }
}

int main() {
  int i, j;
  bool b[10];
  for (;;) {
    scanf("%d%d", &r, &c);
    if (!r && !c)
      break;
    n = 0;
    for (i = 0; i < r; i++)
      for (j = 0; j < c; j++)
        scanf("%d", &s[i][j]);
    search(b, 0);
    printf("%d\\n", n + 1);
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w;
  int s_state[10][10000];

  int cnt, sum, ans;

  int i, j, k;

  while ((cin >> h >> w), h) {
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        cin >> s_state[i][j];
      }
    }

    ans = 0;

    for (k = 0; k < (1 << h); k++) {
      sum = 0;
      for (i = 0; i < w; i++) {
        cnt = 0;
        for (j = 0; j < h; j++) {
          cnt += s_state[j][i] ^ (k >> j & 1);
        }
        sum += max(cnt, h - cnt);
      }
      ans = max(ans, sum);
    }

    cout << ans << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int h, w;
  int s_state[10][1000];

  int cnt, sum, ans;

  int i, j, k;

  while (cin >> h >> w, h) {
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        cin >> s_state[i][j];
      }
    }

    ans = 0;

    for (k = 0; k < (1 << h); k++) {
      sum = 0;
      for (i = 0; i < w; i++) {
        cnt = 0;
        for (j = 0; j < h; j++) {
          cnt += s_state[j][i] ^ (k >> j & 1);
        }
        sum += max(cnt, h - cnt);
      }
      ans = max(ans, sum);
    }

    cout << ans << endl;
  }

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

#include <bits/stdc++.h>
#define MAX_C 10000
using namespace std;
int r, c;
int senbei[1 << 10][MAX_C + 1];

int bitCnt(int n) {
  int cnt = 0;
  while (n > 0) {
    if (n % 2 == 1)
      cnt++;
    n /= 2;
  }
  if (r - cnt < cnt) {
    return r - cnt;
  } else {
    return cnt;
  }
}

int rec(int s, int n) {
  if (senbei[s][n] != -1) {
    return senbei[s][n];
  }
  int tmp = s;
  for (int i = 0; tmp > 0; i++) {
    if (tmp % 2 == 1) {
      for (int j = 0; j < c; j++) {
        int bitpos = 1 << i;
        senbei[s][j] = rec(s ^ bitpos, j) ^ bitpos;
      }
    }
    tmp /= 2;
  }
  return senbei[s][n];
}

int minimam() {
  int ans = 1 << 30;
  int tmp = 0;
  for (int i = 0; i < 1 << r; i++) {
    tmp = 0;
    for (int j = 0; j < c; j++) {
      tmp += bitCnt(senbei[i][j]);
    }
    if (ans > tmp)
      ans = tmp;
  }
  return ans;
}

int main() {
  while (cin >> r >> c) {
    if (c == 0)
      break;
    int tmp[c];
    memset(tmp, 0, sizeof(tmp));
    memset(senbei, -1, sizeof(senbei));
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        tmp[j] = tmp[j] << 1;
        int bit;
        cin >> bit;
        if (bit == 1) {
          tmp[j] = tmp[j] | 1;
        }
      }
    }
    for (int i = 0; i < c; i++) {
      senbei[0][i] = tmp[i];
      // cout << tmp[i] << endl;
    }
    rec((1 << r) - 1, 0);

    cout << r * c - minimam() << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define MAX_C 10000
using namespace std;
int r, c;
int senbei[1 << 10][MAX_C + 1];

int bitCnt(int n) {
  int cnt = 0;
  while (n > 0) {
    if (n % 2 == 1)
      cnt++;
    n /= 2;
  }
  if (r - cnt < cnt) {
    return r - cnt;
  } else {
    return cnt;
  }
}

int rec(int s, int n) {
  if (senbei[s][n] != -1) {
    return senbei[s][n];
  }
  int tmp = s;
  for (int i = 0; tmp > 0; i++) {
    if (tmp % 2 == 1) {
      for (int j = 0; j < c; j++) {
        int bitpos = 1 << i;
        senbei[s][j] = rec(s ^ bitpos, j) ^ bitpos;
      }
    }
    tmp /= 2;
  }
  return senbei[s][n];
}

int minimam() {
  int ans = 1 << 30;
  int tmp = 0;
  for (int i = 0; i < 1 << r; i++) {
    tmp = 0;
    cout << "reset" << endl;
    for (int j = 0; j < c; j++) {
      tmp += bitCnt(senbei[i][j]);
      cout << "tmp is " << tmp << endl;
    }
    if (ans > tmp)
      ans = tmp;
  }
  return ans;
}

int main() {
  while (cin >> r >> c) {
    if (c == 0)
      break;
    int tmp[c];
    memset(tmp, 0, sizeof(tmp));
    memset(senbei, -1, sizeof(senbei));
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        tmp[j] = tmp[j] << 1;
        int bit;
        cin >> bit;
        if (bit == 1) {
          tmp[j] = tmp[j] | 1;
        }
      }
    }
    for (int i = 0; i < c; i++) {
      senbei[0][i] = tmp[i];
      // cout << tmp[i] << endl;
    }
    rec((1 << r) - 1, 0);
    for (int i = 0; i < 1 << r; i++) {
      for (int j = 0; j < c; j++) {
        cout << senbei[i][j];
      }
      cout << endl;
    }
    cout << r * c - minimam() << endl;
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  while (1) {
    int h, w;
    cin >> h >> w;
    if (!h && !w)
      break;
    bool mp[11][10001];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> mp[i][j];

    int ans = 0;
    for (int i = 0; i < (1 << h); i++) {
      int cnt = 0;
      for (int j = 0; j < w; j++) {
        int c = 0;
        for (int k = 0; k < h; k++)
          c += ((i >> k) & 1) ? !mp[k][j] : mp[k][j];
        cnt += max(c, h - c);
      }
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  while (1) {
    int h, w;
    cin >> h >> w;
    if (!h && !w)
      break;

    bool mp[11][1001];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        cin >> mp[i][j];

    int ans = 0;
    for (int i = 0; i < (1 << h); i++) {
      int cnt = 0;
      for (int j = 0; j < w; j++) {
        int c = 0;
        for (int k = 0; k < h; k++)
          c += ((i >> k) & 1) ? !mp[k][j] : mp[k][j];
        cnt += max(c, h - c);
      }
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9 + 7)
void solve(int r, int c) {
  vector<vector<bool>> v(r, vector<bool>(c));
  int ans = 0;
  int in;
  rep(i, r) {
    rep(j, c) {
      cin >> in;
      v[i][j] = in;
    }
  }
  vector<vector<bool>> vvv(r, vector<bool>(c));
  rep(i, pow(2, r)) {
    int a = i;
    rep(j, r) {
      rep(k, c) { vvv[j][k] = ((a & 1) ? v[j][k] : !v[j][k]); }
      a >>= 1;
    }
    int tmp = 0;
    // rep(j,r){
    //     rep(k,c){
    //         cout<<(vvv[j][k]?1:0);
    //     }
    //     cout<<endl;
    // }

    rep(k, c) {
      int t = 0;
      rep(j, r) if (vvv[j][k]) t++;
      tmp += max(t, r - t);
    }
    // cout<<tmp<<endl;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int a, b;
  while (cin >> a >> b, a) {
    solve(a, b);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9 + 7)
void solve(int r, int c) {
  vector<vector<bool>> v(c, vector<bool>(r));
  int ans = 0;
  int in;
  rep(i, r) {
    rep(j, c) {
      cin >> in;
      v[i][j] = in;
    }
  }
  vector<vector<bool>> vvv(c, vector<bool>(r));
  rep(i, pow(2, r)) {
    int a = i;
    rep(j, r) {
      rep(k, c) { vvv[j][k] = ((a & 1) ? v[j][k] : !v[j][k]); }
      a >>= 1;
    }
    int tmp = 0;
    rep(k, c) {
      int t = 0;
      rep(j, r) if (vvv[j][k]) t++;
      tmp += max(t, r - t);
    }
    // cout<<tmp<<endl;
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int a, b, i = 0;
  while (cin >> a >> b, a) {
    solve(a, b);
    i++;
    if (i == 3)
      return 0;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int lastans, ose[10005][15], r, c;
string a = "0", b = "1";
map<string, int> inf;
struct check {
  int wa[10005];
};
void solve(struct check pp, int dp, string str);

int main() {
  struct check po;
  while (1) {
    for (int i = 0; i < 10005; i++)
      po.wa[i] = 0;
    lastans = 0;
    fill(ose[0], ose[10004], 0);
    // inf.clear();

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

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> ose[j][i];
        po.wa[j] += ose[j][i];
      }
    }
    // for(int i=0;i<c;i++)cout << " " << po.wa[i];
    // cout << endl;
    solve(po, 0, "");
    cout << lastans << endl;
  }
  return 0;
}

void solve(struct check pp, int dp, string str) {
  int ans1 = 0, ans2 = 0;
  if (dp == r)
    return;
  else {
    for (int i = 0; i < c; i++) {
      ans1 += max(pp.wa[i], r - pp.wa[i]);
    }
    // cout << "ans=" << ans1 << endl;
    lastans = max(ans1, lastans);
    solve(pp, dp + 1, str + a);

    for (int i = 0; i < c; i++) {
      if (ose[i][dp] == 0)
        pp.wa[i]++;
      else
        pp.wa[i]--;
    }
    for (int i = 0; i < c; i++) {
      ans2 += max(pp.wa[i], r - pp.wa[i]);
    }
    // cout << "ans2=" << ans2 << endl;
    lastans = max(ans2, lastans);
    solve(pp, dp + 1, str + b);
  }
  return;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int lastans, ose[15][10005], r, c;
string a = "0", b = "1";
map<string, int> inf;
struct check {
  int wa[10005];
};
void solve(struct check pp, int dp, string str);

int main() {
  struct check po;
  while (1) {
    for (int i = 0; i < 10005; i++)
      po.wa[i] = 0;
    lastans = 0;
    fill(ose[0], ose[14], 0);
    // inf.clear();

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

    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> ose[j][i];
        po.wa[j] += ose[j][i];
      }
    }
    // for(int i=0;i<c;i++)cout << " " << po.wa[i];
    // cout << endl;
    solve(po, 0, "");
    cout << lastans << endl;
  }
  return 0;
}

void solve(struct check pp, int dp, string str) {
  int ans1 = 0, ans2 = 0;
  if (dp == r)
    return;
  else {
    for (int i = 0; i < c; i++) {
      ans1 += max(pp.wa[i], r - pp.wa[i]);
    }
    // cout << "ans=" << ans1 << endl;
    lastans = max(ans1, lastans);
    solve(pp, dp + 1, str + a);

    for (int i = 0; i < c; i++) {
      if (ose[i][dp] == 0)
        pp.wa[i]++;
      else
        pp.wa[i]--;
    }
    for (int i = 0; i < c; i++) {
      ans2 += max(pp.wa[i], r - pp.wa[i]);
    }
    // cout << "ans2=" << ans2 << endl;
    lastans = max(ans2, lastans);
    solve(pp, dp + 1, str + b);
  }
  return;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

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

#define C_MAX 20000
#define R_MAX 20

bitset<C_MAX> senbei[R_MAX];
int R, C;

int count_col(int i) {
  int count = 0; // 0の数
  for (int p = 0; p < R; p++) {
    if (!senbei[p][i])
      count++;
  }
  return (count > R - count ? count : R - count);
}

int count_all_cols() {
  int count = 0;
  for (int p = 0; p < C; p++) {
    count += count_col(p);
  }
  return count;
}

int solve(int r) {
  if (r > R)
    return count_all_cols();
  int turned, not_turned;
  not_turned = solve(r + 1);
  senbei[r].flip();
  turned = solve(r + 1);
  return (not_turned > turned ? not_turned : turned);
}

int main() {
  while (cin >> R >> C) {
    if (R == 0 && C == 0)
      break;
    for (int i = 0; i < R; i++) {
      senbei[i].reset();
      for (int j = 0; j < C; j++) {
        int tmp;
        cin >> tmp;
        if (tmp) {
          senbei[i].set(j);
        }
      }
    }
    cout << solve(0) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define C_MAX 10001
#define R_MAX 10

bitset<C_MAX> senbei[R_MAX];
int R, C;

int count_col(int i) {
  int count = 0; // 0の数
  for (int p = 0; p < R; p++) {
    if (!senbei[p][i])
      count++;
  }
  return (count > R - count ? count : R - count);
}

int count_all_cols() {
  int count = 0;
  for (int p = 0; p < C; p++) {
    count += count_col(p);
  }
  return count;
}

int solve(int i) {
  if (i > R)
    return count_all_cols();
  int turned, not_turned;
  not_turned = solve(i + 1);
  senbei[i].flip();
  turned = solve(i + 1);
  return (not_turned > turned ? not_turned : turned);
}

int main() {
  while (cin >> R >> C) {
    if (R == 0 && C == 0)
      break;
    for (int i = 0; i < R; i++) {
      senbei[i].reset();
      for (int j = 0; j < C; j++) {
        int tmp;
        cin >> tmp;
        if (tmp) {
          senbei[i].set(j);
        }
      }
    }
    cout << solve(0) << endl;
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int height, width, now_value;

  while (cin >> height >> width) {
    if (width == 0 or height == 0)
      break;

    bool map[height][width];

    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        cin >> now_value;
        if (now_value == 0)
          map[i][j] = false;
        else
          map[i][j] = true;
      }
    }

    // 先?行??，因?行比?少，最多有1024?
    // 然后去?列?行分析，得到最多可能的正面数
    int total = 1 << height;
    int real_max = 0;
    for (int i = 0; i < total; i++) {
      // 翻?
      for (int j = 0; j < height; j++) {
        // 位与?定是否需要翻?
        if (i & (1 << j)) {
          for (int col = 0; col < width; col++)
            map[j][col] = not map[j][col];
        }
      }

      //??最大?
      int max = 0;
      for (int col = 0; col < width; col++) {
        int total_one = 0;
        for (int row = 0; row < height; row++) {
          if (map[row][col])
            total_one++;
        }
        max += (total_one > height - total_one)
                   ? total_one
                   : height - total_one; // 位1的或者可以翻成1的?入
      }

      if (max > real_max)
        real_max = max;

      //?原
      for (int j = 0; j < height; j++) {
        // 位与?定是否需要翻?
        if (i & (1 << j)) {
          for (int col = 0; col < width; col++)
            map[j][col] = not map[j][col];
        }
      }
    }

    cout << real_max << endl;
  }

  return 0;
}

/*
?目附?
翻?子，??一些?子数量是W*H，?次可以反一行或一列。
?能同?最多使多少个?子正面朝上，０表示背面，１表示正面。
其中1 ? R ? 10, 1 ? C ? 10000，行少列多。
*/

Error: MLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int r, c;
bool state[10][10000];
bool linemap[1024][10][10000];
int mapcount;

void creatlinemap() {
  for (int i = 0; i < mapcount; i++) {
    for (int j = 0; j < r; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k < c; k++) {
          linemap[i][j][k] = state[j][k];
        }

      } else {
        for (int k = 0; k < c; k++) {
          linemap[i][j][k] = 1 - state[j][k];
        }
      }
    }
  }
}
int getnum(bool status[10][10000]) {
  int num = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (status[i][j])
        num++;
    }
  }
  return num;
}
int getmax() {
  int max = 0;
  for (int i = 0; i < mapcount; i++) {
    int tmp = getnum(linemap[i]);
    if (tmp > max)
      max = tmp;
  }
  return max;
}
void adjust() {
  for (int i = 0; i < mapcount; i++) {
    for (int j = 0; j < c; j++) {
      int num0 = 0, num1 = 0;
      for (int k = 0; k < r; k++) {
        if (linemap[i][k][j])
          num1++;
        else
          num0++;
      }
      if (num0 > num1) {
        for (int k = 0; k < r; k++) {
          linemap[i][k][j] = 1 - linemap[i][k][j];
        }
      }
    }
  }
}

int main() {

  while (cin >> r >> c) {
    if (r * c == 0)
      return 0;
    mapcount = (int)pow(2.0, r);
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> state[i][j];
      }
    }
    creatlinemap();
    adjust();
    cout << getmax() << endl;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int x[10][10000], H, W;
int main() {
  while (true) {
    cin >> H >> W;
    if (H + W == 0)
      break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++)
        cin >> x[i][j];
    }
    int maxn = 0;
    for (int i = 0; i < (1 << H); i++) {
      int cnt = 0;
      for (int j = 0; j < W; j++) {
        int r = 0;
        for (int k = 0; k < H; k++) {
          int Y = (i / (1 << k)) % 2;
          r += (x[k][j] + Y) % 2;
        }
        cnt += max(r, H - r);
      }
      maxn = max(maxn, cnt);
    }
    cout << maxn << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int x[10][10000], H, W;
int main() {
  while (true) {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++)
        cin >> x[i][j];
    }
    int maxn = 0;
    for (int i = 0; i < (1 << H); i++) {
      int cnt = 0;
      for (int j = 0; j < W; j++) {
        int r = 0;
        for (int k = 0; k < H; k++) {
          int Y = (i / (1 << k)) % 2;
          r += (x[k][j] + Y) % 2;
        }
        cnt += max(r, H - r);
      }
      maxn = max(maxn, cnt);
    }
    cout << maxn << endl;
  }
  return 0;
}