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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for (__typeof(a) i = a; i <= b; i++)
#define inp_arr(a, n)                                                          \\
  for (__typeof(n) i = 0; i < n; ++i) {                                        \\
    cin >> a[i];                                                               \\
  }
#define debug_arr(a, n)                                                        \\
  {                                                                            \\
    {                                                                          \\
      for (__typeof(n) i = 0; i < n; ++i) {                                    \\
        cout << a[i] << " ";                                                   \\
      }                                                                        \\
      cout << "\\n";                                                            \\
    }                                                                          \\
  }

ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}

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

  // #ifndef ONLINE_JUDGE
  // freopen("inp.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // #endif

  int h, w, k;
  cin >> h >> w >> k;

  string s[h];
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }

  int total = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#')
        ++total;
    }
  }

  int cc1 = 0;

  bitset<10> bh(0);

  int ans = 0;
  while (cc1 < 100) {
    int r = bh.to_ulong();
    cc1 += 1;

    bitset<10> bw(0);
    int cc2 = 0;

    while (cc2 < 100) {

      int c = bw.to_ulong();
      cc2 += 1;

      int temp = 0;
      for (int i = 0; i < h; ++i) {
        if (bh[i] == 1) {
          for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#')
              ++temp;
          }
        }
      }
      for (int i = 0; i < w; ++i) {
        if (bw[i] == 1) {
          for (int j = 0; j < h; ++j) {
            if (s[j][i] == '#')
              ++temp;
          }
        }
      }
      for (int i = 0; i < h; ++i) {
        if (bh[i] == 1) {
          for (int j = 0; j < w; ++j) {
            if (bw[j] == 1) {
              if (s[i][j] == '#')
                --temp;
            }
          }
        }
      }

      if (total - temp == k)
        ++ans;
      // cout<<temp<<"\\n";

      int ff = 1;
      for (int i = 0; i < w; ++i) {
        if (bw[i] == 0) {
          ff = 0;
          break;
        }
      }
      if (ff)
        break;

      c += 1;
      bw = c;
    }

    int f = 1;
    for (int i = 0; i < h; ++i) {
      if (bh[i] == 0) {
        f = 0;
        break;
      }
    }
    if (f)
      break;
    r += 1;
    bh = r;
  }
  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define F first
#define S second
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for (__typeof(a) i = a; i <= b; i++)
#define inp_arr(a, n)                                                          \\
  for (__typeof(n) i = 0; i < n; ++i) {                                        \\
    cin >> a[i];                                                               \\
  }
#define debug_arr(a, n)                                                        \\
  {                                                                            \\
    {                                                                          \\
      for (__typeof(n) i = 0; i < n; ++i) {                                    \\
        cout << a[i] << " ";                                                   \\
      }                                                                        \\
      cout << "\\n";                                                            \\
    }                                                                          \\
  }

ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res % mod;
}

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

  // #ifndef ONLINE_JUDGE
  // freopen("inp.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // #endif

  int h, w, k;
  cin >> h >> w >> k;

  string s[w];
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
  }

  int total = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#')
        ++total;
    }
  }

  int cc1 = 0;

  bitset<10> bh(0);

  int ans = 0;
  while (cc1 < 100) {
    int r = bh.to_ulong();
    cc1 += 1;

    bitset<10> bw(0);
    int cc2 = 0;

    while (cc2 < 100) {

      int c = bw.to_ulong();
      cc2 += 1;

      int temp = 0;
      for (int i = 0; i < h; ++i) {
        if (bh[i] == 1) {
          for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#')
              ++temp;
          }
        }
      }
      for (int i = 0; i < w; ++i) {
        if (bw[i] == 1) {
          for (int j = 0; j < h; ++j) {
            if (s[j][i] == '#')
              ++temp;
          }
        }
      }
      for (int i = 0; i < h; ++i) {
        if (bh[i] == 1) {
          for (int j = 0; j < w; ++j) {
            if (bw[j] == 1) {
              if (s[i][j] == '#')
                --temp;
            }
          }
        }
      }

      if (total - temp == k)
        ++ans;
      // cout<<temp<<"\\n";

      int ff = 1;
      for (int i = 0; i < w; ++i) {
        if (bw[i] == 0) {
          ff = 0;
          break;
        }
      }
      if (ff)
        break;

      c += 1;
      bw = c;
    }

    int f = 1;
    for (int i = 0; i < h; ++i) {
      if (bh[i] == 0) {
        f = 0;
        break;
      }
    }
    if (f)
      break;
    r += 1;
    bh = r;
  }
  cout << ans << "\\n";

  return 0;
}