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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(), r.end()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-10;

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

int h, w;
vector<string> s;

int d[100][100];
bool outOfRange(int y, int x) {
  if (x < 0 || x >= w || y < 0 || y >= h) {
    return true;
  }
  return false;
}

void dfs(int y, int x) {
  // cout<<y<<" "<<x<<endl;
  for (int i = 2; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (outOfRange(ny, nx))
      continue;
    int c = s[ny][nx] - '0';
    if (d[ny][nx] <= d[y][x] + c)
      continue;
    d[ny][nx] = d[y][x] + c;
    dfs(ny, nx);
  }
}

int main() {
  string t;
  cin >> h >> w;
  rep(i, h) {
    cin >> t;
    s.pb(t);
  }
  rep(i, 100) {
    rep(j, 100) { d[i][j] = INF; }
  }
  d[0][0] = s[0][0] - '0';
  dfs(0, 0);
  // for(int i = 0; i < h; i++){
  // 	for(int j = 0; j < w; j++){
  // 		cout<<" "<<d[i][j];
  // 	}
  // 	cout<<endl;
  // }
  cout << d[h - 1][w - 1] << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(), r.end()
#define fi first
#define se second
#define println(X) cout << X << endl;
#define DBG(X) cout << #X << " : " << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-10;

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

int h, w;
vector<string> s;

int d[100][100];
bool outOfRange(int y, int x) {
  if (x < 0 || x >= w || y < 0 || y >= h) {
    return true;
  }
  return false;
}

void dfs(int y, int x) {
  // cout<<y<<" "<<x<<endl;
  for (int i = 2; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    int c = s[ny][nx] - '0';
    if (outOfRange(ny, nx))
      continue;
    if (d[ny][nx] <= d[y][x] + c)
      continue;
    d[ny][nx] = d[y][x] + c;
    dfs(ny, nx);
  }
}

int main() {
  string t;
  cin >> h >> w;
  rep(i, h) {
    cin >> t;
    s.pb(t);
  }
  rep(i, 100) {
    rep(j, 100) { d[i][j] = INF; }
  }
  d[0][0] = s[0][0] - '0';
  dfs(0, 0);
  // for(int i = 0; i < h; i++){
  // 	for(int j = 0; j < w; j++){
  // 		cout<<" "<<d[i][j];
  // 	}
  // 	cout<<endl;
  // }
  cout << d[h - 1][w - 1] << endl;
}