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

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

long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod);

int main() {
  int H, W, K, O = 0;
  cin >> H >> W >> K;
  int C[H][W], T[H][W];
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    for (int j = 0; j < W; j++) {
      if (s[j] == '#') {
        C[i][j] = 1;
        T[i][j] = 1;
      } else {
        C[i][j] = 0;
        T[i][j] = 0;
      }
    }
  }
  int A = int(Exp(2, H + W, 999999999));
  int count = 0;
  for (int i = 0; i < A; i++) {
    for (int j = 0; j < H; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k < W; k++) {
          T[j][k] = 0;
        }
      }
    }

    for (int j = H; j < H + W; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k < H; k++) {
          T[k][j - H] = 0;
        }
      }
    }

    for (int j = 0; j < H; j++) {
      for (int k = 0; k < W; k++) {
        if (T[j][k] == 1) {
          count++;
        }
        T[j][k] = C[j][k];
      }
    }
    if (count == K) {
      O++;
      //      cout << i <<endl;
    }
    count = 0;
  }

  cout << O << endl;
  return 0;
}

long long int Exp(long long int exp_n, long long int exp_e,
                  long long int exp_mod) {
  long long int exp_o = 1;
  long long int exp_x = exp_n;
  long long int exp_tmp;

  while (0 < exp_e) {
    exp_tmp = exp_e / 2;
    if (exp_e - exp_tmp * 2 == 1) {
      exp_o = exp_o * exp_x;
      if (exp_o > exp_mod) {
        exp_o = exp_o % exp_mod;
      }
    }

    exp_x = exp_x * exp_x;
    if (exp_x > exp_mod) {
      exp_x = exp_x % exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Error: 0

Fixed submission:

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

long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod);

int main() {
  int H, W, K, O = 0;
  cin >> H >> W >> K;
  int C[H][W], T[H][W];
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    for (int j = 0; j < W; j++) {
      if (s[j] == '#') {
        C[i][j] = 1;
        T[i][j] = 1;
      } else {
        C[i][j] = 0;
        T[i][j] = 0;
      }
    }
  }
  int A = int(Exp(2, H + W, 999999999));
  int count = 0;
  for (int i = 0; i < A; i++) {
    for (int j = 0; j < H; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k < W; k++) {
          T[j][k] = 0;
        }
      }
    }

    for (int j = H; j < H + W; j++) {
      if (i & (1 << j)) {
        for (int k = 0; k < W; k++) {
          T[k][j - H] = 0;
        }
      }
    }

    for (int j = 0; j < H; j++) {
      for (int k = 0; k < W; k++) {
        if (T[j][k] == 1) {
          count++;
        }
        T[j][k] = C[j][k];
      }
    }
    if (count == K) {
      O++;
      //      cout << i <<endl;
    }
    count = 0;
  }

  cout << O << endl;
  return 0;
}

long long int Exp(long long int exp_n, long long int exp_e,
                  long long int exp_mod) {
  long long int exp_o = 1;
  long long int exp_x = exp_n;
  long long int exp_tmp;

  while (0 < exp_e) {
    exp_tmp = exp_e / 2;
    if (exp_e - exp_tmp * 2 == 1) {
      exp_o = exp_o * exp_x;
      if (exp_o > exp_mod) {
        exp_o = exp_o % exp_mod;
      }
    }

    exp_x = exp_x * exp_x;
    if (exp_x > exp_mod) {
      exp_x = exp_x % exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}