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

#include <bits/stdc++.h>
#define db1(x) cout << #x << "=" << x << '\\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\\n'
#define db3(x, y, z)                                                           \\
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << '\\n'
#define vll vector<ll>
// #define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define pii pair<int, int>
#define vec(a) vector<a>
#define all(a) a.begin(), a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
// #define int unsigned long long
// #define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define int long long
using namespace std;
// using ll = unsigned long long;
ll md = MD;
// ll M=1073741824;
ll M = 1e9 + 7;
// ll exp(ll a,ll b){ll
// r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return
// (r+md)%md;}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll Min(int a, int b) {
  if (a < b)
    return a;
  return b;
}
ll Max(int a, int b) {
  if (a > b)
    return a;
  return b;
}
ll powM(ll a, ll b) {
  if (a == 1)
    return 1;
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % M;
    a = (a * a) % M;
    b = b >> 1;
  }
  return ans;
}
ll power(ll a, ll b) {
  if (a == 1)
    return 1;
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a);
    a = (a * a);
    b = b >> 1;
  }
  return ans;
}
const int INF = 1000000000000000000;

// always try to hack ur soln before submitting (penalty-50 wrong submission 50
// min sochle isse aacha)
//  Abe n*m ke grid main y ke coordinates m se akm hone chahiye na ke n se
int row[6], col[6], ans = 0;

vector<string> v(6);
int n, m, k;
void fun(int x, int y) {
  int x1 = x, y1 = y;
  for (int i = 0; i < 6; ++i)
    row[i] = col[i] = 0;
  int cnt = 0;
  while (x > 0) {
    if (x & 1)
      row[cnt] = 1;
    x = x >> 1;
    ++cnt;
  }
  cnt = 0;
  while (y > 0) {
    if (y & 1)
      col[cnt] = 1;
    y = y >> 1;
    ++cnt;
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!(row[i] || col[j]) && (v[i][j] == '#'))
        ++cnt;
    }
  }
  //	db3(cnt,x1,y1);
  if (cnt == k) {

    ++ans;
  }
}

int32_t main() {
  IOS;
  int t;
  //	cin>>t;
  t = 1;
  while (t--) {
    cin >> n >> m >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
      cin >> v[i];

    for (int i = 0; i < power(2, n); ++i) {
      for (int j = 0; j < power(2, m); ++j) {
        fun(i, j);
      }
    }
    cout << ans << "\\n";
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define db1(x) cout << #x << "=" << x << '\\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\\n'
#define db3(x, y, z)                                                           \\
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \\
       << '\\n'
#define vll vector<ll>
// #define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= b; ++i)
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define pii pair<int, int>
#define vec(a) vector<a>
#define all(a) a.begin(), a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
// #define int unsigned long long
// #define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define int long long
using namespace std;
// using ll = unsigned long long;
ll md = MD;
// ll M=1073741824;
ll M = 1e9 + 7;
// ll exp(ll a,ll b){ll
// r=1;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return
// (r+md)%md;}
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll Min(int a, int b) {
  if (a < b)
    return a;
  return b;
}
ll Max(int a, int b) {
  if (a > b)
    return a;
  return b;
}
ll powM(ll a, ll b) {
  if (a == 1)
    return 1;
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % M;
    a = (a * a) % M;
    b = b >> 1;
  }
  return ans;
}
ll power(ll a, ll b) {
  if (a == 1)
    return 1;
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a);
    a = (a * a);
    b = b >> 1;
  }
  return ans;
}
const int INF = 1000000000000000000;

// always try to hack ur soln before submitting (penalty-50 wrong submission 50
// min sochle isse aacha)
//  Abe n*m ke grid main y ke coordinates m se akm hone chahiye na ke n se
int row[6], col[6], ans = 0;

vector<string> v(6);
int n, m, k;
int fun(int x, int y) {
  int x1 = x, y1 = y;
  memset(row, 0, sizeof(row));
  memset(col, 0, sizeof(col));
  int cnt = 0;
  while (x > 0) {
    if (x & 1)
      row[cnt] = 1;
    x = x >> 1;
    ++cnt;
  }
  cnt = 0;
  while (y > 0) {
    if (y & 1)
      col[cnt] = 1;
    y = y >> 1;
    ++cnt;
  }
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!(row[i] || col[j]) && (v[i][j] == '#'))
        ++cnt;
    }
  }
  //	db3(cnt,x1,y1);
  if (cnt == k) {

    ++ans;
  }
}

int32_t main() {
  IOS;
  int t;
  //	cin>>t;
  t = 1;
  while (t--) {
    cin >> n >> m >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i)
      cin >> v[i];

    for (int i = 0; i < power(2, n); ++i) {
      for (int j = 0; j < power(2, m); ++j) {
        fun(i, j);
      }
    }
    cout << ans << "\\n";
  }
}