Problem p02735 (C++)

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

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORS(i, a, b, c) for (int i = a; i < b; i += c)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a - 1; i >= b; i--)
#define FORE(i, b) for (auto &i : b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i * i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a, n) a, a + n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a)                                                                \
  a.back();                                                                    \
  a.RB()
#define QBACK(a)                                                               \
  a.top();                                                                     \
  a.pop()
#define PRINT(a)                                                               \
  FORE(i, a) cout << i << " ";                                                 \
  cout << endl

#define PB push_back
#define RB pop_back
#define RF pop_front
#define INS insert
#define F first
#define S second
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue

#define IO                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int main() {
  IO;
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];
  mi DP(H, vi(W, 10000));
  DP[0][0] = (s[0][0] == '#');
  REP(i, H) {
    REP(j, W) {
      if (i)
        DP[i][j] = DP[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#');
      if (j)
        MIN(DP[i][j], DP[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
    }
  }
  cout << DP[W - 1][H - 1] << endl;
}


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

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORS(i, a, b, c) for (int i = a; i < b; i += c)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a - 1; i >= b; i--)
#define FORE(i, b) for (auto &i : b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i * i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a, n) a, a + n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a)                                                                \
  a.back();                                                                    \
  a.RB()
#define QBACK(a)                                                               \
  a.top();                                                                     \
  a.pop()
#define PRINT(a)                                                               \
  FORE(i, a) cout << i << " ";                                                 \
  cout << endl

#define PB push_back
#define RB pop_back
#define RF pop_front
#define INS insert
#define F first
#define S second
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue

#define IO                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

int main() {
  IO;
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  REP(i, H) cin >> s[i];
  mi DP(H, vi(W, 10000));
  DP[0][0] = (s[0][0] == '#');
  REP(i, H) {
    REP(j, W) {
      if (i)
        DP[i][j] = DP[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#');
      if (j)
        MIN(DP[i][j], DP[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
    }
  }
  cout << DP[H - 1][W - 1] << endl;
}