alexjercan/bugnet huggingface dataset:
Problem p00448 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>

using namespace std;

int data[10][10000];
int dp[1 << 10][10000];

int main() {
  int c, r;
  while (cin >> r >> c && r && c) {
    fill((int *)data, (int *)data + 10 * 10000, 0);
    fill((int *)dp, (int *)dp + (1 << 10) * 10000, 0);
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> data[i][j];
      }
    }

    for (int i = 0; i < c; i++) {
      if (i > 0) {
        for (int j = 0; j < 1 << (r); j++) {
          int tmp1 = 0, tmp2 = 0;
          for (int k = 0; k < r; k++) {
            int t = data[k][i];
            if ((j & (1 << k)) != 0)
              t++;
            if ((t + 1) % 2 == 0)
              tmp2++;
            if (t % 2 == 0)
              tmp1++;
          }

          dp[j][i] = dp[j][i - 1] + max(tmp1, tmp2);
        }
      }

      else {
        for (int j = 0; j < 1 << (r); j++) {
          dp[j][i] = 0;
          int tmp1 = 0, tmp2 = 0;
          for (int k = 0; k < r; k++) {
            int t = data[k][i];
            if ((j & (1 << k)) != 0)
              t++;
            if ((t + 1) % 2 == 0)
              tmp2++;
            if (t % 2 == 0)
              tmp1++;
          }
          dp[j][i] = max(tmp1, tmp2);
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < 1 << (r); i++) {
      ans = max(ans, dp[i][c - 1]);
    }

    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>

using namespace std;

int data[15][15000];
int dp[1 << 11][15000];

int main() {
  int c, r;
  while (cin >> r >> c && r && c) {
    fill((int *)data, (int *)data + 15 * 15000, 0);
    fill((int *)dp, (int *)dp + (1 << 11) * 15000, 0);
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> data[i][j];
      }
    }

    for (int i = 0; i < c; i++) {
      if (i > 0) {
        for (int j = 0; j < 1 << (r); j++) {
          int tmp1 = 0, tmp2 = 0;
          for (int k = 0; k < r; k++) {
            int t = data[k][i];
            if ((j & (1 << k)) != 0)
              t++;
            if ((t + 1) % 2 == 0)
              tmp2++;
            if (t % 2 == 0)
              tmp1++;
          }

          dp[j][i] = dp[j][i - 1] + max(tmp1, tmp2);
        }
      }

      else {
        for (int j = 0; j < 1 << (r); j++) {
          dp[j][i] = 0;
          int tmp1 = 0, tmp2 = 0;
          for (int k = 0; k < r; k++) {
            int t = data[k][i];
            if ((j & (1 << k)) != 0)
              t++;
            if ((t + 1) % 2 == 0)
              tmp2++;
            if (t % 2 == 0)
              tmp1++;
          }
          dp[j][i] = max(tmp1, tmp2);
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < 1 << (r); i++) {
      ans = max(ans, dp[i][c - 1]);
    }

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

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int osenbei[10][10000];
int flag[10];
int C, R, ans;

int count() {
  int cnt = 0;
  for (int i = 0; i < C; ++i) {
    int b = 0;
    for (int j = 0; j < R; ++j) {
      if (flag[j] == 1 && osenbei[j][i] == 0)
        ++b;
      else if (flag[j] == 0 && osenbei[j][i] == 1)
        ++b;
    }
    if (b > R - b)
      cnt += b;
    else
      cnt += (R - b);
  }
  return cnt;
}

void solve(int k) {
  if (k == R) {
    ans = max(ans, count());
    return;
  }
  flag[k] = 0;
  solve(k + 1);
  flag[k] = 1;
  solve(k + 1);
  return;
}

int main() {
  // cin.tie(false);
  // ios::sync_with_stdio(false);
  while (cin >> R >> C && C != 0 && R != 0) {
    ans = 0;
    for (int i = 0; i < R; ++i) {
      flag[i] = 0;
      for (int j = 0; j < C; ++j) {
        cin >> osenbei[i][j];
      }
    }
    solve(0);
    cout << ans << "\\n";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int osenbei[10][10000];
int flag[10];
int C, R, ans;

int count() {
  int cnt = 0;
  for (int i = 0; i < C; ++i) {
    int b = 0;
    for (int j = 0; j < R; ++j) {
      if (flag[j] == 1 && osenbei[j][i] == 0)
        ++b;
      else if (flag[j] == 0 && osenbei[j][i] == 1)
        ++b;
    }
    if (b > R - b)
      cnt += b;
    else
      cnt += R - b;
  }
  return cnt;
}

void solve(int k) {
  if (k == R) {
    ans = max(ans, count());
    return;
  }
  flag[k] = 0;
  solve(k + 1);
  flag[k] = 1;
  solve(k + 1);
  return;
}

int main() {
  // cin.tie(false);
  // ios::sync_with_stdio(false);
  while (cin >> C >> R && C != 0 && R != 0) {
    ans = 0;
    for (int i = 0; i < R; ++i) {
      flag[i] = 0;
      for (int j = 0; j < C; ++j) {
        cin >> osenbei[i][j];
      }
    }
    solve(0);
    cout << ans << "\\n";
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

// #define int long long
#define FOR(i, j, k) for (int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

int r, c;
int n[10][10000], ans = 0;
bool use[10];

void dfs(int now) {
  if (now == r) {
    int res = 0;
    rep(j, c) {
      int count = 0;
      rep(i, r) {
        if ((use[i] && n[i][j]) || (!use[i] && !n[i][j]))
          ++count;
      }
      res += (r - count < count) ? count : r - count;
    }
    chmax(ans, res);
    return;
  }
  use[now] = true;
  dfs(now + 1);
  use[now] = false;
  dfs(now + 1);
}

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

  while ((cin >> r >> c), r | c) {
    ans = 0;
    rep(i, r) rep(j, c) cin >> n[i][j];
    dfs(0);
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// #define int long long
#define FOR(i, j, k) for (int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

int r, c;
int n[5][10000], ans = 0;
bool use[10];

void dfs(int now) {
  if (now == r) {
    int res = 0;
    rep(j, c) {
      int count = 0;
      rep(i, r) {
        if ((use[i] && n[i][j]) || (!use[i] && !n[i][j]))
          ++count;
      }
      res += (r - count < count) ? count : r - count;
    }
    chmax(ans, res);
    return;
  }
  use[now] = true;
  dfs(now + 1);
  use[now] = false;
  dfs(now + 1);
}

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

  while ((cin >> r >> c), r | c) {
    ans = 0;
    rep(i, r) rep(j, c) cin >> n[i][j];
    dfs(0);
    cout << ans << endl;
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

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

const int maxn = 1e4 + 10;
bitset<maxn> cookie[10];

int main() {
  int R, C;
  while (cin >> R >> C && (R || C)) {
    int i, j;
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++) {
        bool upward;
        cin >> upward;
        cookie[i][j] = upward;
      }

    int r = 1 << R;
    int res = 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < R; j++) {
        if (i & (1 << j))
          cookie[j].flip();
      }

      int ans = 0;
      for (int j = 0; j < C; j++) {
        int up = 0;
        for (int k = 0; k < R; k++) {
          if (cookie[k][j])
            up++;
        }
        ans += max(up, R - up);
      }

      res = max(ans, res);

      for (int j = 0; j < R; j++) {
        if (i & (1 << j))
          cookie[j].flip();
      }
    }
    printf("%d\\n", res);
  }
}

Error: WA

Fixed submission:

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

const int maxn = 1e4 + 10;
bitset<maxn> cookie[10];

int main() {
  int R, C;
  while (cin >> R >> C && (R || C)) {
    int i, j;
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++) {
        bool upward;
        cin >> upward;
        cookie[i][j] = upward;
      }

    int r = 1 << R;
    int res = 0;
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < R; j++) {
        if (i & (1 << j))
          cookie[i].flip();
      }

      int ans = 0;
      for (int j = 0; j < C; j++) {
        int up = 0;
        for (int k = 0; k < R; k++) {
          if (cookie[k][j])
            up++;
        }
        ans += max(up, R - up);
      }

      res = max(ans, res);

      for (int j = 0; j < R; j++) {
        if (i & (1 << j))
          cookie[j].flip();
      }
    }
    printf("%d\\n", res);
  }
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int c, r;
  while (cin >> r >> c) {
    if (c == 0 && r == 0) {
      break;
    }
    vector<vector<int>> data(r, vector<int>(c));
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> data[i][j];
      }
    }
    int ll = 2 << r;
    long long int ccc = 0;
    for (int i = 0; i < ll; i++) {
      vector<vector<int>> d2;
      d2 = data;
      for (int j = 0; j < r; j++) {
        for (int k = 0; k < c; k++) {
          if ((i & (2 << j)) != 0) {
            d2[j][k] ^= 1;
          }
        }
      }
      long long int cc = 0;
      for (int k = 0; k < c; k++) {
        int ss = 0;
        for (int j = 0; j < r; j++) {
          ss += d2[j][k];
        }
        cc += (long long int)max(ss, r - ss);
      }
      ccc = max(ccc, cc);
    }
    cout << ccc << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int count(vector<vector<int>> hyou, int r, int n) {
  int counter = 0;
  int counter2;
  for (int i = 0; i < r; i++) {
    counter2 = 0;
    for (int j = 0; j < n; j++) {
      if (hyou[i][j] == 1) {
        counter2++;
      }
    }
    if (counter2 < n - counter2) {
      counter2 = n - counter2;
    }
    counter += counter2;
  }
  return counter;
}

int keisan(vector<vector<int>> hyou, int r, int n, int limit) {
  if (limit == 0) {
    return count(hyou, r, n);
  } else {
    vector<vector<int>> hyou2 = hyou;
    for (int i = 0; i < r; i++) {
      hyou2[i][limit - 1] = 1 - hyou2[i][limit - 1];
    }
    return max(keisan(hyou, r, n, limit - 1), keisan(hyou2, r, n, limit - 1));
  }
}

int main() {
  int r, c;
  while (cin >> r >> c) {
    if (r == 0 && c == 0) {
      break;
    }
    vector<vector<int>> hyou(r, vector<int>(c));
    for (int i = 0; i < r; i++) {
      for (int j = 0; j < c; j++) {
        cin >> hyou[i][j];
      }
    }
    cout << keisan(hyou, r, c, c) << endl;
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, ma, sum, mai;
  int a[10][10000];
  while (scanf("%d %d", &h, &w), h != 0 && w != 0) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    ma = 0;
    for (int i = 0; i < (1 << h); i++) {
      sum = 0;
      for (int j = 0; j < w; j++) {
        mai = 0;
        for (int k = 0; k < h; k++) {
          if ((i & (1 << k)) == 0)
            mai += !(a[k][j] == 1);
          else
            mai += (a[k][j] == 1);
        }
        sum += max(mai, h - mai);
      }
      ma = max(ma, sum);
    }
    printf("%d\\n", ma);
  }
  return (0);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, ma, sum, mai;
  int a[10000][10];
  while (scanf("%d %d", &h, &w), h != 0 && w != 0) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d", &a[i][j]);
      }
    }

    ma = 0;
    for (int i = 0; i < (1 << w); i++) {
      sum = 0;
      for (int j = 0; j < h; j++) {
        mai = 0;
        for (int k = 0; k < w; k++)
          mai += (i & (1 << k)) != 0 ? !(a[j][k] == 1) : (a[j][k] == 1);
        sum += max(mai, w - mai);
      }
      ma = max(ma, sum);
    }
    printf("%d\\n", ma);
  }
  return (0);
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

// Solution for 0525: Osenbei
#include <algorithm>
#include <iostream>
using namespace std;
int r, c, ans, sum;
int cracker[11][10001], save[11][10001];
void solve(int i) {
  sum = 0;
  for (int j = 1; j <= c; j++) {
    save[i][j] = cracker[i][j];
    if (cracker[i][j])
      cracker[i][j] = 0;
    else
      cracker[i][j] = 1;
    int count = 0;
    for (int k = 1; k <= r; k++) {
      if (cracker[k][j])
        count++;
    }
    if (count > r / 2)
      sum += count;
    else
      sum += r - count;
  }
  ans = max(ans, sum);
  if (i == r)
    return;
  for (int j = i + 1; j <= r; j++) {
    solve(j);
    for (int k = 1; k <= c; k++) {
      cracker[j][k] = save[j][k];
    }
  }
}
int main() {
  while (true) {
    cin >> r >> c;
    if (!r && !c)
      return 0;
    ans = 0;
    for (int i = 1; i <= r; i++) {
      for (int j = 1; j <= c; j++) {
        cin >> cracker[i][j];
      }
    }
    for (int i = 1; i <= r; i++) {
      solve(i);
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

// Solution for 0525: Osenbei
#include <algorithm>
#include <iostream>
using namespace std;
int r, c, ans, sum;
int cracker[11][100000], save[11][1000100];
void solve(int i) {
  sum = 0;
  for (int j = 1; j <= c; j++) {
    save[i][j] = cracker[i][j];
    if (cracker[i][j])
      cracker[i][j] = 0;
    else
      cracker[i][j] = 1;
    int count = 0;
    for (int k = 1; k <= r; k++) {
      if (cracker[k][j])
        count++;
    }
    if (count > r / 2)
      sum += count;
    else
      sum += r - count;
  }
  ans = max(ans, sum);
  if (i == c)
    return;
  for (int j = i + 1; i <= c; i++) {
    solve(j);
    for (int k = 1; k <= c; k++) {
      cracker[j][k] = save[j][k];
    }
  }
}
int main() {
  while (true) {
    cin >> r >> c;
    if (!r && !c)
      return 0;
    ans = 0;
    for (int i = 1; i <= r; i++) {
      for (int j = 1; j <= c; j++) {
        cin >> cracker[i][j];
      }
    }
    for (int i = 1; i <= r; i++) {
      solve(i);
    }
    cout << ans << endl;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
input:
2 5
0 1 0 1 0
1 0 0 0 1
3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1
0 0
output:
9
15
*/
#include <algorithm>
#include <bitset>
#include <cstdio>

using namespace std;

const int MAX_R = 10;
const int MAX_C = 10000;

//&#36755;入
int R, C;
bitset<MAX_C> a[MAX_R];

int ans;

void dfs(int k) {
  if (k == R) {
    // 在当前行翻&#36716;&#30830;定的情况下，由于列数量&#36739;大，并不真正翻&#36716;列
    int result = 0;
    for (int j = 0; j < C; j++) {
      int upNum = 0;
      for (int i = 0; i < R; i++) {
        if (a[i][j])
          upNum++;
      }
      result += max(upNum, R - upNum); // 虚&#25311;翻&#36716;
    }
    ans = max(ans, result);
    return;
  }
  // 不翻&#36716;第k行
  dfs(k + 1);
  // 翻&#36716;第k行
  a[k].flip();
  dfs(k + 1);
  //&#22797;原
  a[k].flip();
}

void solve() {
  // 初始化
  ans = 0;
  // 深度&#20248;先遍&#21382;
  dfs(0);
  printf("%d\\n", ans);
}

int main(int argc, char const *argv[]) {

  while (scanf("%d %d", &R, &C)) {
    if (R == 0 && C == 0)
      break;

    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        bool tmp;
        scanf("%d", &tmp);
        a[i][j] = tmp;
      }
    }
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

/*
input:
2 5
0 1 0 1 0
1 0 0 0 1
3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1
0 0
output:
9
15
*/
#include <algorithm>
#include <cstdio>

using std::max;

const int MAX_R = 10;
const int MAX_C = 10000;

//&#36755;入
int R, C;
bool a[MAX_R][MAX_C];

int ans;

void dfs(int k) {
  if (k == R) {
    // 在当前行翻&#36716;&#30830;定的情况下，由于列数量&#36739;大，并不真正翻&#36716;列
    int result = 0;
    for (int j = 0; j < C; j++) {
      int upNum = 0;
      for (int i = 0; i < R; i++) {
        if (a[i][j])
          upNum++;
      }
      result += max(upNum, R - upNum); // 虚&#25311;翻&#36716;
    }
    ans = max(ans, result);
    return;
  }
  // 不翻&#36716;第k行
  dfs(k + 1);
  // 翻&#36716;第k行
  for (int j = 0; j < C; j++)
    a[k][j] = !a[k][j];
  dfs(k + 1);
  //&#22797;原
  for (int j = 0; j < C; j++)
    a[k][j] = !a[k][j];
}

void solve() {
  // 初始化
  ans = 0;
  // 深度&#20248;先遍&#21382;
  dfs(0);
  printf("%d\\n", ans);
}

int main(int argc, char const *argv[]) {

  while (scanf("%d %d", &R, &C)) {
    if (R == 0 && C == 0)
      break;

    for (int i = 0; i < R; i++) {
      for (int j = 0; j < C; j++) {
        scanf("%d", &a[i][j]);
      }
    }
    solve();
  }

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

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

int R, C, senbei[10000][10], f[10], num;

void rec(int);
int count();

int main() {
  int i, j;
  while (cin >> R >> C, R | C) {
    for (j = 0; j < R; j++)
      for (i = 0; i < C; i++)
        cin >> senbei[i][j];
    rec(0);
    cout << num << endl;
  }
}

void rec(int k) {
  if (k == R) {
    num = max(num, count());
    return;
  }
  f[k] = 0;
  rec(k + 1);
  f[k] = 1;
  rec(k + 1);
}

int count() {
  int n = 0, i, j;
  for (i = 0; i < C; i++) {
    int cnt = 0;
    for (j = 0; j < R; j++)
      cnt += senbei[i][j] ^ f[j];
    n += max(cnt, R - cnt);
  }
  return n;
}

Error: 0

Fixed submission:


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

int R, C, senbei[11][10001], f[11], num;

void rec(int);
int count();

int main() {
  int i, j;
  while (cin >> R >> C, R | C) {
    for (j = 0; j < R; j++)
      for (i = 0; i < C; i++)
        cin >> senbei[i][j];
    rec(0);
    cout << num << endl;
  }
}

void rec(int k) {
  if (k == R) {
    num = max(num, count());
    return;
  }
  f[k] = 0;
  rec(k + 1);
  f[k] = 1;
  rec(k + 1);
}

int count() {
  int n = 0, i, j;
  for (i = 0; i < C; i++) {
    int cnt = 0;
    for (j = 0; j < R; j++)
      cnt += senbei[i][j] ^ f[j];
    n += max(cnt, R - cnt);
  }
  return n;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int r, c;
  while (cin >> r >> c && r) {
    bool data[r][c];
    rep(i, r) rep(j, c) data[i][j] = 0;
    int ret = 0;
    rep(i, r) rep(j, c) { cin >> data[i][j]; }

    rep(bit, (1 << r)) {
      int val[c][2];
      rep(i, c) rep(j, 2) val[i][j] = 0;

      rep(j, r) {
        if ((1 << j) & bit) {
          rep(i, c) { val[i][data[j][i] ^ 1]++; }
        } else {
          rep(i, c) { val[i][data[j][i]]++; }
        }
      }
      int sum = 0;
      rep(i, c) { sum += max(val[i][0], val[i][1]); }
      ret = max(sum, ret);
    }

    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef vector<vector<int>> NODE;
int main() {
  queue<NODE> Q;
  int cnt;
  int w, h, mx;
  while (cin >> h >> w, h) {
    map<NODE, bool> done;
    mx = 0;
    NODE data(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> data[i][j];
      }
    }

    Q.push(data);
    while (Q.size()) {
      cnt = 0;
      NODE q = Q.front();
      Q.pop();
      for (int i = 0; i < h; i++) {
        cnt += count(q[i].begin(), q[i].end(), 1);
        for (int j = 0; j < w; j++)
          q[i][j] ^= 1;
        if (!done[q]) {
          Q.push(q);
          done[q] = true;
        }
        for (int j = 0; j < w; j++)
          q[i][j] ^= 1;
      }
      for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++)
          q[j][i] ^= 1;
        if (!done[q]) {
          Q.push(q);
          done[q] = true;
        }
        for (int j = 0; j < h; j++)
          q[j][i] ^= 1;
      }
      mx = max(cnt, mx);
    }
    cout << mx << endl;
  }
}
Problem p00448 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int t[1024], i, j, k, r, c, a[10000], m, z;
main() {
  for (; i < 1024; t[i++] = k)
    for (k = j = 10; j--; i & 1 << j || --k)
      ;
  for (; cin >> r >> c, i = r; cout << m << '\\n') {
    for (fill(a, a + c, m = 0); i--;)
      for (j = c; j--; k ? a[j] |= 1 << i : 0)
        cin >> k;
    for (i = 1 << r; i--; m = max(m, z), z = 0)
      for (j = c; j--; z += max(k, r - k))
        k = t[a[j] ^ i];
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int t[1024], i, j, k, r, c, a[10000], m, z;
int main() {
  for (; i < 1024; t[i++] = k)
    for (k = j = 10; j--; i & 1 << j || --k)
      ;
  for (; cin >> c >> r, i = r; cout << m << '\\n') {
    for (m = 0; i--;)
      for (j = c; j--; k ? a[j] |= 1 << i : 0)
        cin >> k;
    for (i = 1 << r; i--; m = max(m, z), z = 0)
      for (j = c; j--; z += max(k, r - k))
        k = t[a[j] ^ i];
  }
  return 0;
}
Problem p00448 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define sint(i) scanf("%d", &i);
#define sintt(i, j) scanf("%d%d", &i, &j);
#define sinttt(i, j, k) scanf("%d%d%d", &i, &j, &k);

using namespace std;

int masu[10000];

int main() {
  while (1) {
    int n, m;
    sintt(n, m);

    if (n == 0)
      break;

    rep(i, 10000) { masu[i] = 0; }

    rep(i, n) {
      rep(j, m) {
        int a;
        sint(a);
        masu[j] += a << i;
      }
    }

    int maxi = 0;

    rep(i, 1 << n) {
      int cont = 0;
      rep(j, m) {
        int cont2 = 0;
        // printf("%d-",masu[j]^i);
        rep(k, n) {
          // printf("%d",(masu[j]^i)&(1<<k));
          if (((masu[j] ^ i) & (1 << k)) > 0) {
            cont2++;
          }
        }
        // printf("-%d ",cont2);
        cont += max(cont2, n - cont2);
      } // puts("");
      maxi = max(maxi, cont);
    }

    printf("%d\\n", maxi);
  }
}
/*
3 6
1 0 0 0 1 0
1 1 1 0 1 0
1 0 1 1 0 1

*/

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>

using namespace std;

int n, m;
int sen[11][10001];
int maxi;

void saiki(int dep) {
  if (dep >= m) {
    int cont = 0;
    for (int i = 0; i < m; i++) {
      int con[2];
      con[0] = 0;
      con[1] = 0;
      for (int j = 0; j < n; j++) {
        con[sen[j][i]]++;
      }
      cont += max(con[0], con[1]);
    }
    if (cont > maxi) {
      maxi = cont;
    }
    return;
  }

  saiki(dep + 1);
  for (int i = 0; i < n; i++) {
    if (sen[i][dep] == 0) {
      sen[i][dep] = 1;
    } else {
      sen[i][dep] = 0;
    }
  }

  saiki(dep + 1);
  for (int i = 0; i < n; i++) {
    if (sen[i][dep] == 0) {
      sen[i][dep] = 1;
    } else {
      sen[i][dep] = 0;
    }
  }
}

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &sen[i][j]);
      }
    }
    maxi = 0;
    saiki(0);

    printf("%d\\n", maxi);
  }
}