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

#include "bits/stdc++.h"
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X) ((X) * (X))
#define CUBE(X) ((X) * (X) * (X))
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
  reader(t);
  reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
  reader(t);
  reader(u);
  reader(v);
}

void writer(int a, char c) {
  printf("%d", a);
  putchar(c);
}
void writer(ll a, char c) {
  printf("%lld", a);
  putchar(c);
}
void writer(double a, char c) {
  printf("%.20lf", a);
  putchar(c);
}
void writer(char a[]) { printf("%s", a); };
void writer(char a[], char c) {
  printf("%s", a);
  putchar(c);
};
void writer(char a, char c) {
  putchar(a);
  putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\\n'); }
template <class T, class U> void writerLn(T t, U u) {
  writer(t, ' ');
  writer(u, '\\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
  writer(t, ' ');
  writer(u, ' ');
  writer(v, '\\n');
}
template <class T> void writerArr(T x[], int n) {
  int i;
  if (!n) {
    putchar('\\n');
    return;
  }
  rep(i, n - 1) writer(x[i], ' ');
  writer(x[n - 1], '\\n');
}
template <class T> void writerVec(vector<T> x) {
  int n = x.size();
  int i;
  if (!n) {
    putchar('\\n');
    return;
  }
  rep(i, n - 1) writer(x[i], ' ');
  writer(x[n - 1], '\\n');
}

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
// #define int ll

bool test = 1;

//............................
#define MAX 300000
signed main() {
  int i, j, k, l;
  while (1) {
    int n, m;
    set<pair<int, int>> s;
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      s.insert(make_pair(x, y));
    }
    cin >> m;
    int nowx = 10;
    int nowy = 10;
    rep(i, m) {
      char d;
      int l;
      cin >> d >> l;
      int dir;
      switch (d) {
      case 'N':
        dir = 0;
        break;
      case 'E':
        dir = 1;
        break;
      case 'S':
        dir = 2;
        break;
      case 'W':
        dir = 3;
        break;
      }
      rep(j, l) {
        nowx += dx[dir];
        nowy += dy[dir];
        s.erase(make_pair(nowx, nowy));
      }
    }
    if (s.size() == 0)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始！ */
/* 入力終了！ */

void syori(int a[30][30], int i, int j, int r, int *n) {
  if (a[i][j]) {
    *n -= a[i][j];
    a[i][j] = 0;
  }
}
int main() {
  int i, j, k, l;
  int o;
  int cnt = 1;
  int x;
  int y;
  char c;
  int r;
  static int a[30][30];
  static int judge[100000];
  int n, m;
  for (o = 0;; o++) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d", &x, &y);
      a[x][y]++;
    }
    scanf("%d", &m);
    i = 10;
    j = 10;
    for (k = 0; k < m; k++) {
      scanf(" %c %d", &c, &r);
      printf("%c %d\\n", c, r);
      if (c == 'N') {
        for (l = 0; l < r; l++) {
          j++;
          syori(a, i, j, r, &n);
        }
      } else if (c == 'E') {
        for (l = 0; l < r; l++) {
          i++;
          syori(a, i, j, r, &n);
        }
      } else if (c == 'S') {
        for (l = 0; l < r; l++) {
          i--;
          syori(a, i, j, r, &n);
        }
      } else if (c == 'W') {
        for (l = 0; l < r; l++) {
          j--;
          syori(a, i, j, r, &n);
        }
      }
    }
    if (n == 0)
      judge[o] = 1;
  }
  for (i = 0; i < o; i++) {
    if (judge[i])
      printf("Yes\\n");
    else
      printf("No\\n");
  }
  return 0;
}