Problem p03273 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};

struct edge {
  ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy;
vector<vector<char>> field;
vector<vector<int>> dist;
// vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int>> Matrix;

const ll INF = 1e18;

int main() {

  int H, W;
  cin >> H >> W;
  int h = H, w = W;
  int Hcount = 0;
  int Vcount = 0;
  vector<vector<char>> a(H + 10, vector<char>('0', W + 10));
  REP(i, H) REP(j, W) cin >> a[i][j];
  vector<int> trueH(H + 10, 0), trueW(W + 10, 0);

  vector<bool> row(h, false);
  vector<bool> col(w, false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i]) {
      for (int j = 0; j < w; j++) {
        if (col[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define REP1(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define pow(x) x *x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};

struct edge {
  ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy;
vector<vector<char>> field;
vector<vector<int>> dist;
// vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int>> Matrix;

const ll INF = 1e18;

int main() {

  int H, W;
  cin >> H >> W;
  int h = H, w = W;
  int Hcount = 0;
  int Vcount = 0;
  // vector<vector<char>> a(H+10, vector<char>('0', W+10));
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  vector<int> trueH(H + 10, 0), trueW(W + 10, 0);

  vector<bool> row(h, false);
  vector<bool> col(w, false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i]) {
      for (int j = 0; j < w; j++) {
        if (col[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/