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

#include <iostream>
#include <vector>

int main() {
  int H, W, K;
  std::cin >> H >> W >> K;

  std::vector<std::vector<char>> c(H, std::vector<char>(W, 0));
  int blackCount = 0;
  std::vector<int> hBlackCount(H, 0);
  std::vector<int> vBlackCount(W, 0);
  for (int i = 0; i != H; i++) {
    for (int j = 0; j != W; j++) {
      std::cin >> c[i][j];
      if (c[i][j] == '#') {
        blackCount++;
        hBlackCount[i]++;
        vBlackCount[j]++;
      }
    }
  }

  int result = 0;
  for (int hBit = 0; hBit != 1 << H; hBit++) {
    std::vector<int> horizontal;
    for (int i = 0; i != H; i++) {
      if (hBit & (1 << i)) {
        horizontal.push_back(i);
      }
    }

    int black = blackCount;
    for (auto e : horizontal)
      black -= hBlackCount[e];

    for (int vBit = 0; vBit != 1 << W; vBit++) {
      std::vector<int> vertical;
      for (int j = 0; j != W; j++) {
        if (vBit & (1 << j)) {
          vertical.push_back(j);
        }
      }

      int black2 = black;
      for (auto e : vertical) {
        black2 -= vBlackCount[e];

        for (auto e2 : horizontal) {
          if (c[e2][e] == '#') {
            black2++;
          }
        }
      }

      if (black2 == K) {
        result++;
      }
    }
  }

  std::cout << result << std::endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  int H, W, K;
  std::cin >> H >> W >> K;

  std::vector<std::vector<char>> c(W, std::vector<char>(H, 0));
  int blackCount = 0;
  std::vector<int> hBlackCount(H, 0);
  std::vector<int> vBlackCount(W, 0);
  for (int i = 0; i != H; i++) {
    for (int j = 0; j != W; j++) {
      std::cin >> c[i][j];
      if (c[i][j] == '#') {
        blackCount++;
        hBlackCount[i]++;
        vBlackCount[j]++;
      }
    }
  }

  int result = 0;
  for (int hBit = 0; hBit != 1 << H; hBit++) {
    std::vector<int> horizontal;
    for (int i = 0; i != H; i++) {
      if (hBit & (1 << i)) {
        horizontal.push_back(i);
      }
    }

    int black = blackCount;
    for (auto e : horizontal)
      black -= hBlackCount[e];

    for (int vBit = 0; vBit != 1 << W; vBit++) {
      std::vector<int> vertical;
      for (int j = 0; j != W; j++) {
        if (vBit & (1 << j)) {
          vertical.push_back(j);
        }
      }

      int black2 = black;
      for (auto e : vertical) {
        black2 -= vBlackCount[e];

        for (auto e2 : horizontal) {
          if (c[e2][e] == '#') {
            black2++;
          }
        }
      }

      if (black2 == K) {
        result++;
      }
    }
  }

  std::cout << result << std::endl;

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

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

int main() {
  int H, W, k, ans = 0;
  cin >> H >> W >> k;
  vector<string> c(H);
  for (int i = 0; i < H; i++)
    cin >> c[i];

  for (int bith = 0; bith < (1 << H); ++bith)
    for (int bitw = 0; bitw < (1 << W); ++bitw) {
      int count = 0;
      for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w) {
          if ((bith >> h) & 1)
            continue;
          if ((bitw >> w) & 1)
            continue;
          if (c[h][w] == '#')
            count++;
        }
      if (count == k)
        ans++;
    }
  cout << ans;
}

Error: -11

Fixed submission:

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

int main() {
  int H, W, k, ans = 0;
  cin >> H >> W >> k;
  vector<string> c;
  for (int i = 0; i < H; i++)
    cin >> c[i];

  for (int bith = 0; bith < (1 << H); bith++)
    for (int bitw = 0; bitw < (1 << W); bitw++) {
      int count = 0;
      for (int h = 0; h < H; h++)
        for (int w = 0; w < W; w++) {
          if (h >> bith & 1)
            continue;
          if (w >> bitw & 1)
            continue;
          if (c[h][w] == '#')
            count++;
        }
      if (count == k)
        ans++;
    }
  cout << ans;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
char c[10][10];
bool a[10];
bool b[10];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < (1 << m); j++) {
      int cnt = 0;
      for (int ii = 0; ii < n; ii++) {
        a[ii] = 0;
        if (i & (1 << ii)) {
          a[ii] = 1;
        }
      }
      for (int jj = 0; jj < m; jj++) {
        b[jj] = 0;
        if (j & (1 << jj)) {
          b[jj] = 1;
        }
      }
      for (int ii = 0; ii < n; ii++) {
        for (int jj = 0; jj < m; jj++) {
          if (!a[ii] && !b[jj] && c[ii][jj] == '#')
            cnt++;
        }
      }
      if (cnt == k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#pragma GCC optimize(3)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
char c[10][10];
bool vis[5][5];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int black = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#')
        black++;
    }
  }
  vector<int> v;
  vector<int> t;
  for (int i = 0; i < n; i++) {
    v.push_back(i);
  }
  for (int i = 0; i < m; i++) {
    t.push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int repeat = 0;
      while (next_permutation(v.begin(), v.end())) {
        while (next_permutation(t.begin(), t.end())) {
          memset(vis, 0, sizeof(vis));
          int tmp = 0;
          for (int i2 = 0; i2 <= i; i2++) {
            for (int j2 = 0; j < m; j2++) {
              if (!vis[v[i2]][j2] && c[v[i2]][j2] == '#') {
                tmp++;
              }
              vis[v[i2]][j2] = 1;
            }
          }
          for (int i2 = 0; i2 <= j; i2++) {
            for (int j2 = 0; j2 < n; j2++) {
              if (!vis[t[j2]][i2] && c[t[j2]][i2] == '#') {
                tmp++;
              }
              vis[t[j2]][i2] = 1;
            }
          }
          if (tmp + k == black) {
            repeat++;
          }
        }
      }
      int kkk = 1;
      for (int ii = i; ii >= 1; ii--) {
        kkk *= ii;
      }
      for (int ii = j; ii >= 1; ii--) {
        kkk *= ii;
      }
      ans += repeat / kkk;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> vec(6);
  rep(i, H) { cin >> vec.at(i); }
  auto vec_sec = vec;
  int count = 0;
  int answer = 0;
  rep(tmp, (1 << 7)) {
    bitset<7> xs(tmp);
    if (xs.test(H)) {
      break;
    }
    rep(tm, (1 << 7)) {
      bitset<7> ys(tm);
      if (ys.test(W)) {
        break;
      }
      vec_sec = vec;
      count = 0;
      rep(i, H) {
        if (xs.test(i)) {
          rep(j, W) { vec_sec.at(i).at(j) = '0'; }
        }
      }

      rep(i, W) {
        if (ys.test(i)) {
          rep(j, H) { vec_sec.at(j).at(i) = '0'; }
        }
      }

      rep(i, H) {
        rep(j, W) {
          if (vec_sec.at(i).at(j) == '#') {
            count++;
          }
        }
      }

      if (count == K) {
        answer++;
      }
    }
  }
SKIP:
  cout << answer << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> vec(6);
  rep(i, H) { cin >> vec.at(i); }
  auto vec_sec = vec;
  int count = 0;
  int answer = 0;
  rep(tmp, (1 << 6)) {
    bitset<6> xs(tmp);
    if (xs.test(H)) {
      break;
    }
    rep(tm, (1 << 6)) {
      bitset<6> ys(tm);
      if (ys.test(W)) {
        break;
      }
      vec_sec = vec;
      count = 0;
      rep(i, H) {
        if (xs.test(i)) {
          rep(j, W) { vec_sec.at(i).at(j) = '0'; }
        }
      }

      rep(i, W) {
        if (ys.test(i)) {
          rep(j, H) { vec_sec.at(j).at(i) = '0'; }
        }
      }

      rep(i, H) {
        rep(j, W) {
          if (vec_sec.at(i).at(j) == '#') {
            count++;
          }
        }
      }

      if (count == K) {
        answer++;
      }
    }
  }
SKIP:
  cout << answer << endl;
}
Problem p02614 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main() {
  cout << fixed << setprecision(10);
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> c(H);
  rep(i, H) { cin >> c[i]; }
  int ans = 0;
  for (int tmp = 0; tmp < (1 << H); tmp++) {
    bitset<6> s(tmp);
    for (int tmp2 = 0; tmp2 < (1 << W); tmp2++) {
      bitset<6> t(tmp2);
      int sum = 0;
      rep(i, H) {
        rep(j, W) {
          if (s.test(i) && t.test(j)) {
            if (c[i][j] == '#') {
              sum++;
            }
          }
        }
      }
      if (sum == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int main() {
  cout << fixed << setprecision(10);
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> c(H, vector<char>(W));
  rep(i, H) {
    rep(j, W) { cin >> c[i][j]; }
  }
  int ans = 0;
  for (int tmp = 0; tmp < (1 << 6); tmp++) {
    bitset<6> s(tmp);
    for (int tmp2 = 0; tmp2 < (1 << 6); tmp++) {
      bitset<6> t(tmp2);
      int sum = 0;
      rep(i, H) {
        rep(j, W) {
          if (s.test(i) && t.test(j)) {
            if (c[i][j] == '#') {
              sum++;
            }
          }
        }
      }
      if (sum == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

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

// 初見×
// bit全探索について理解すること
int main() {
  cin >> H >> W >> K;
  vector<string> s(H);
  rep(i, H) cin >> s[i];
  int ans = 0;
  rep(is, 1 << H) rep(js, 1 << W) {
    int cnt = 0;
    rep(i, H) rep(j, W) {
      if ((is >> i) & 1)
        continue;
      if ((js >> j) & 1)
        continue;
      if (s[i][j] == '#')
        cnt++;
    }
    if (cnt == K)
      ans++;
  }
  cout << ans << endl;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int H, W, K;
vector<string> s;
;

// 初見×
// bit全探索について理解すること
int main() {
  cin >> H >> W >> K;
  rep(i, H) cin >> s[i];
  int ans = 0;
  rep(is, 1 << H) rep(js, 1 << W) {
    int cnt = 0;
    rep(i, H) rep(j, W) {
      if ((is >> i) & 1)
        continue;
      if ((js >> j) & 1)
        continue;
      if (s[i][j] == '#')
        cnt++;
    }
    if (cnt == K)
      ans++;
  }
  cout << ans << endl;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<string> vec(h);
  for (int i = 0; i < h; i++) {
    cin >> vec.at(i);
    // cout << vec.at(i) << endl;
  }

  int ans = 0;
  for (int mask_h = 0; mask_h < (1 << h) - 1; mask_h++) {
    for (int mask_w = 0; mask_w < (1 << w) - 1; mask_w++) {
      // マスクするパターン(2^h * 2^w 通り)

      // 全マスのmask_hとmask_w以外の黒色をカウントする
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          // マスク対象の行・列は除外する
          if (mask_h & (1 << i))
            continue;
          if (mask_w & (1 << j))
            continue;
          // 黒色のマスをカウントする
          if (vec.at(i).at(j) == '#')
            cnt++;
        }
      }
      // cout << mask_h << ":" << mask_w << "...マスク後の黒マスは" << cnt <<
      // endl;
      if (cnt == k)
        ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<string> vec(w);
  for (int i = 0; i < w; i++) {
    cin >> vec.at(i);
    // cout << vec.at(i) << endl;
  }

  int ans = 0;
  for (int mask_h = 0; mask_h < (1 << h) - 1; mask_h++) {
    for (int mask_w = 0; mask_w < (1 << w) - 1; mask_w++) {
      // マスクするパターン(2^h * 2^w 通り)

      // 全マスのmask_hとmask_w以外の黒色をカウントする
      int cnt = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          // マスク対象の行・列は除外する
          if (mask_h & (1 << i))
            continue;
          if (mask_w & (1 << j))
            continue;
          // 黒色のマスをカウントする
          if (vec.at(i).at(j) == '#')
            cnt++;
        }
      }
      // cout << mask_h << ":" << mask_w << "...マスク後の黒マスは" << cnt <<
      // endl;
      if (cnt == k)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, need;
  long long ans = 0;
  cin >> h >> w >> need;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < (1 << h); i++) {
    for (int j = 0; j < (1 << w); j++) {
      int bl = 0;
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (!(i & (1 << k)) && !(j & (1 << l)) && s[k][l] == '#')
            bl++;
        }
      }
      if (bl == need)
        ans++;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, need;
  long long ans = 0;
  cin >> h >> w >> need;
  vector<string> s(w);
  for (int i = 0; i < w; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < (1 << h); i++) {
    for (int j = 0; j < (1 << w); j++) {
      int bl = 0;
      for (int k = 0; k < h; k++) {
        for (int l = 0; l < w; l++) {
          if (!(i & (1 << k)) && !(j & (1 << l)) && s[k][l] == '#')
            bl++;
        }
      }
      if (bl == need)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02614 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  int i, j;
  vector<vector<char>> c(H, vector<char>(W));
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int count = 0;
  int ans = 0;
  int bitX, bitY;
  for (bitY = 0; bitY < (1 << H); bitY++) {
    for (bitX = 0; bitX < (1 << W); bitX++) {
      count = 0;

      for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
          if (!(bitY & (1 << i)) && !(bitX & (1 << j)) &&
              c.at(i).at(j) == '#') {
            count++;
          }
        }
      }

      if (count == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  int i, j;
  vector<vector<char>> c(H, vector<char>(W));
  for (i = 0; i < H; i++) {
    for (j = 0; j < W; j++) {
      cin >> c.at(i).at(j);
    }
  }
  int count = 0, ans = 0;
  int bitX = 0, bitY = 0;
  for (bitY = 0; bitY < (1 << H); bitY++) {
    for (bitX = 0; bitY < (1 << W); bitX++) {
      count = 0;

      for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
          if (!(bitY & (1 << i)) && !(bitX & (1 << j)) &&
              c.at(i).at(j) == '#') {
            count++;
          }
        }
      }

      if (count == K) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  int ans = 0;
  for (int i = 0; i < h; i++)
    cin >> s[i];
  for (int i = 0; i < (1 << h); i++) {
    for (int j = 0; j < (1 << w); j++) {
      int count = 0;
      for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (i >> x & 1)
            continue;
          if (j >> y & 1)
            continue;
          if (s[x][y] == '#')
            count++;
        }
      }
      if (count == k)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  int ans = 0;
  for (int i = 0; i < (1 << h); i++) {
    for (int j = 0; j < (1 << w); j++) {
      int count = 0;
      for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (i >> x & 1)
            continue;
          if (j >> y % 1)
            continue;
          if (s[i][j] == '#')
            count++;
        }
      }
      if (count == k)
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02614 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  int h, w, k, count = 0;
  std::cin >> h >> w >> k;
  char c[100][100];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cin >> c[i][j];
    }
  }

  for (int maskH = 0; maskH < (1 << h); maskH++) { // bit全探索 '1'の行を塗る
    for (int maskW = 0; maskW < (1 << w); maskW++) {
      int black = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (((maskH >> i) & 1) == 1) {
            continue;
          } // i行目が赤なら飛ばす
          if (((maskW >> j) & 1) == 1) {
            continue;
          }
          if (c[i][j] == '#') {
            black++;
          }
        }
      }
      if (black == k) {
        count++;
      }
    }
  }

  std::cout << count << std::endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

int main() {
  int h, w, k, count = 0;
  std::cin >> h >> w >> k;
  char c[w + 1][h + 1];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      std::cin >> c[i][j];
    }
  }

  for (int maskH = 0; maskH < (1 << h); maskH++) { // bit全探索 '1'の行を塗る
    for (int maskW = 0; maskW < (1 << w); maskW++) {
      int black = 0;
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (((maskH >> i) & 1) == 1) {
            continue;
          } // i行目が赤なら飛ばす
          if (((maskW >> j) & 1) == 1) {
            continue;
          }
          if (c[i][j] == '#') {
            black++;
          }
        }
      }
      if (black == k) {
        count++;
      }
    }
  }

  std::cout << count << std::endl;

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

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<char> a(h * w);
  for (int i = 0; i < h * w; i++)
    cin >> a[i];

  vector<char> reset(h * w);
  for (int i = 0; i < h * w; i++)
    reset[i] = a[i];

  int count = 0;
  int ans = 0;

  for (int bit = 0; bit < (1 << h); bit++) {

    for (int bitw = 0; bitw < (1 << w); bitw++) {

      for (int i = 0; i < h; i++) {
        if (bit & (1 << i)) {
          for (int j = w * i; j < w * (i + 1); j++)
            a[j] = 'R';
        }
      }

      for (int i = 0; i < w; i++) {
        if (bitw & (1 << i)) {
          for (int j = i; j <= h * w; j += w)
            a[j] = 'R';
        }
      }

      for (int i = 0; i < h * w; i++) {
        if (a[i] == '#')
          count++;
      }
      if (count == k)
        ans++;
      count = 0;

      for (int i = 0; i < h * w; i++)
        a[i] = reset[i];
    }
  }

  cout << ans << endl;

  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;

  vector<char> a(h * w);
  for (int i = 0; i < h * w; i++)
    cin >> a[i];

  vector<char> reset(h * w);
  for (int i = 0; i < h * w; i++)
    reset[i] = a[i];

  int count = 0;
  int ans = 0;

  for (int bit = 0; bit < (1 << h); bit++) {

    for (int bitw = 0; bitw < (1 << w); bitw++) {

      for (int i = 0; i < h; i++) {
        if (bit & (1 << i)) {
          for (int j = w * i; j < w * (i + 1); j++)
            a[j] = 'R';
        }
      }

      for (int i = 0; i < w; i++) {
        if (bitw & (1 << i)) {
          for (int j = i - 1; j <= h * w - 1; j += w)
            a[j] = 'R';
        }
      }

      for (int i = 0; i < h * w; i++) {
        if (a[i] == '#')
          count++;
      }
      if (count == k)
        ans++;
      count = 0;

      for (int i = 0; i < h * w; i++)
        a[i] = reset[i];
    }
  }

  cout << ans << endl;

  return 0;
}