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

#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define endl "\\n"
#define pb push_back
#define se second
#define fi first
#define int long long
#define pi pair<int, int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define For(i, n) for (int i = 0; i < n; i++)
#define pie = 3.14159265358979323846264338327950
const int mod = 1e9 + 7;

void findn(vector<vector<int>> &vecn, int i, vector<int> &temp1, int &n) {
  if (temp1.size() != 0)
    vecn.pb(temp1);
  for (int j = i; j < n; j++) {
    temp1.pb(j);
    findn(vecn, j + 1, temp1, n);
    temp1.pop_back();
  }
}

void findm(vector<vector<int>> &vecm, int i, vector<int> &temp2, int &m) {
  if (temp2.size() != 0)
    vecm.pb(temp2);
  for (int j = i; j < m; j++) {
    temp2.pb(j);
    findm(vecm, j + 1, temp2, m);
    temp2.pop_back();
  }
}

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<char>> ar(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ar[i][j];
    }
  }
  vector<vector<int>> vecn;
  vector<vector<int>> vecm;
  vector<int> temp1;
  vector<int> temp2;
  findn(vecn, 0, temp1, n);
  findm(vecm, 0, temp2, m);
  int ans = 0;
  // cout<<vecn.size()<<endl;
  // cout<<vecm.size()<<endl;
  for (int i = 0; i < (int)vecn.size(); i++) {
    for (int j = 0; j < (int)vecm.size(); j++) {
      int cnt = 0;
      for (int x = 0; x < (int)vecn[i].size(); x++) {
        for (int y = 0; y < (int)vecm[j].size(); y++) {
          if (ar[vecn[i][x]][vecm[j][y]] == '#') {
            cnt++;
          }
        }
      }
      if (cnt == k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define endl "\\n"
#define pb push_back
#define se second
#define fi first
#define int long long
#define pi pair<int, int>
#define vpi vector<pi>
#define vvi vector<vpi>
#define For(i, n) for (int i = 0; i < n; i++)
#define pie = 3.14159265358979323846264338327950
const int mod = 1e9 + 7;

void findn(vector<vector<int>> &vecn, int i, vector<int> &temp1, int &n) {
  if (temp1.size() != 0)
    vecn.pb(temp1);
  for (int j = i; j < n; j++) {
    temp1.pb(j);
    findn(vecn, j + 1, temp1, n);
    temp1.pop_back();
  }
}

void findm(vector<vector<int>> &vecm, int i, vector<int> &temp2, int &m) {
  if (temp2.size() != 0)
    vecm.pb(temp2);
  for (int j = i; j < m; j++) {
    temp2.pb(j);
    findm(vecm, j + 1, temp2, m);
    temp2.pop_back();
  }
}

int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<char>> ar(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ar[i][j];
    }
  }
  vector<vector<int>> vecn;
  vector<vector<int>> vecm;
  vector<int> temp1;
  vector<int> temp2;
  findn(vecn, 0, temp1, n);
  findm(vecm, 0, temp2, m);
  int ans = 0;
  // cout<<vecn.size()<<endl;
  // cout<<vecm.size()<<endl;
  for (int i = 0; i < (int)vecn.size(); i++) {
    for (int j = 0; j < (int)vecm.size(); j++) {
      int cnt = 0;
      for (int x = 0; x < (int)vecn[i].size(); x++) {
        for (int y = 0; y < (int)vecm[i].size(); y++) {
          if (ar[vecn[i][x]][vecm[j][y]] == '#') {
            cnt++;
          }
        }
      }
      if (cnt == k) {
        ans++;
      }
    }
  }
  cout << ans + 1 << endl;
  return 0;
}