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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define rep(i, x) for (int i = 0; i < x; i++)
int n, m;
string f[205];
ll ans = 1;
bitset<205> mat[10005];
ll c[5][5];
int gauss() {
  int cur = 0;
  for (int i = 0; i < 205; i++) {
    for (int j = cur; j < 10005; j++) {
      if (mat[j][i] == true) {
        swap(mat[j], mat[cur]);
        goto nxt;
      }
    }
    continue;
  nxt:;
    for (int j = cur + 1; j < 10005; j++) {
      if (mat[j][i] == true) {
        mat[j] ^= mat[cur];
      }
    }
    cur++;
  }
  return cur;
}
int main() {
  cin >> n >> m;
  rep(i, n) cin >> f[i];
  if (n % 2 == 1) {
    rep(i, m) {
      if (i > m - 1 - i)
        break;
      if (f[n / 2][i] != f[n / 2][m - 1 - i]) {
        ans = ans * 2ll % mod;
        break;
      }
    }
  }
  if (m % 2 == 1) {
    rep(i, n) {
      if (i > n - 1 - i)
        break;
      if (f[i][m / 2] != f[n - 1 - i][m / 2]) {
        ans = ans * 2ll % mod;
        break;
      }
    }
  }
  rep(i, 5) rep(j, i + 1) {
    if (j == 0 || j == i)
      c[i][j] = 1;
    else
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  int row = 0;
  rep(i, n / 2) rep(j, m / 2) {
    map<char, int> S;
    S[f[i][j]] += 1;
    S[f[n - 1 - i][j]] += 1;
    S[f[i][m - 1 - j]] += 1;
    S[f[n - 1 - i][m - 1 - j]] += 1;
    int cur = 0;
    ll mul = 1;
    for (map<char, int>::iterator it = S.begin(); it != S.end(); it++) {
      mul = mul * c[cur + it->second][cur];
      cur += it->second;
    }
    if (mul == 24) {
      ans = ans * 12LL % mod;
      mat[row][i] = 1;
      mat[row][j + n / 2 + 2] = 1;
      row++;
    } else {
      ans = ans * mul % mod;
    }
  }
  int free = gauss();
  rep(i, free) ans = ans * 2LL % mod;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define rep(i, x) for (int i = 0; i < x; i++)
int n, m;
string f[205];
ll ans = 1;
bool mat[405][405];
ll c[5][5];
int gauss() {
  int cur = 0;
  for (int i = 0; i < 405; i++) {
    for (int j = cur; j < 405; j++) {
      if (mat[j][i] == true) {
        for (int k = 0; k < 405; k++)
          swap(mat[j][k], mat[cur][k]);
        goto nxt;
      }
    }
    continue;
  nxt:;
    for (int j = cur + 1; j < 405; j++) {
      if (mat[j][i] == true) {
        for (int k = 0; k < 405; k++)
          mat[j][k] ^= mat[cur][k];
      }
    }
    cur++;
  }
  return cur;
}
int main() {
  cin >> n >> m;
  rep(i, n) cin >> f[i];
  if (n % 2 == 1) {
    rep(i, m) {
      if (i > m - 1 - i)
        break;
      if (f[n / 2][i] != f[n / 2][m - 1 - i]) {
        ans = ans * 2ll % mod;
        break;
      }
    }
  }
  if (m % 2 == 1) {
    rep(i, n) {
      if (i > n - 1 - i)
        break;
      if (f[i][m / 2] != f[n - 1 - i][m / 2]) {
        ans = ans * 2ll % mod;
        break;
      }
    }
  }
  rep(i, 5) rep(j, i + 1) {
    if (j == 0 || j == i)
      c[i][j] = 1;
    else
      c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
  }
  int row = 0;
  rep(i, n / 2) rep(j, m / 2) {
    map<char, int> S;
    S[f[i][j]] += 1;
    S[f[n - 1 - i][j]] += 1;
    S[f[i][m - 1 - j]] += 1;
    S[f[n - 1 - i][m - 1 - j]] += 1;
    int cur = 0;
    ll mul = 1;
    for (map<char, int>::iterator it = S.begin(); it != S.end(); it++) {
      mul = mul * c[cur + it->second][cur];
      cur += it->second;
    }
    if (mul == 24) {
      ans = ans * 12LL % mod;
      mat[row][i] = 1;
      mat[row][j + n] = 1;
      row++;
    } else {
      ans = ans * mul % mod;
    }
  }
  int free = gauss();
  rep(i, free) ans = ans * 2LL % mod;
  cout << ans << endl;
}