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

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

signed main() {
  int n;
  while (scanf("%lld", &n)) {
    if (n == 0)
      break;
    int board[30][30] = {};
    int r, c;
    rep(i, 0, n) {
      scanf("%lld%lld", &c, &r);
      r = 20 - r;
      board[r][c] = 1;
    }

    int m;
    scanf("%lld", &m);
    string st = "SNEW";
    char d;
    int t;
    int rr = 10, cc = 10;
    int cnt = 0;
    rep(i, 0, m) {
      scanf(" %c %lld", &d, &t);
      // printf("debug: m = %lld, input = (%c, %lld)\\n", m, d, t);
      int p = st.find(d);
      rep(j, 0, t) {
        rr += dx[p], cc += dy[p];
        if (board[rr][cc])
          cnt++;
        board[rr][cc] = 0;
      }
    }
    if (cnt == n)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
bool operator<(const P &a, const P &b) {
  return a.X != b.X ? a.X < b.X : a.Y < b.Y;
}
} // namespace std

signed main() {
  int n;
  while (scanf("%lld", &n), n) {
    int board[30][30] = {};
    bool visited[30][30] = {};
    visited[9][9] = true;
    int r, c;
    rep(i, 0, n) {
      scanf("%lld%lld", &c, &r);
      r--;
      c--;
      board[r][c] = 1;
    }

    int m;
    scanf("%lld", &m);
    string st = "NSEW";
    char d;
    int t;
    r = 9, c = 9;
    int cnt = 0;
    if (board[9][9] == 1)
      cnt = 1;
    rep(i, 0, m) {
      scanf(" %c %lld", &d, &t);
      // printf("debug: m = %lld, input = (%c, %lld)\\n", m, d, t);
      int p = st.find(d);
      rep(j, 0, t) {
        r += dx[p], c += dy[p];
        if (visited[r][c])
          continue;
        visited[r][c] = true;
        if (board[r][c])
          cnt++;
      }
    }
    if (cnt == n)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}