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

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

struct P {
  int x, y;
};

vector<P> list;
int input() {
  int N;
  cin >> N;
  list.clear();
  if (N == 0)
    return false;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    list.push_back(P{a, b});
  }
  return true;
}

int vx[] = {0, 1, 0, -1};
int vy[] = {1, 0, -1, 0};

bool solve() {
  int M;
  cin >> M;
  P r = P{10, 10};
  vector<int> use;
  use.resize(list.size());
  for (int i = 0; i < use.size(); i++) {
    use[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    char c;
    int d;
    cin >> c >> d;
    int v;
    switch (c) {
    case 'N':
      v = 0;
      break;
    case 'E':
      v = 1;
      break;
    case 'S':
      v = 2;
      break;
    case 'W':
      v = 3;
      break;
    }
    int xx = r.x + vx[v] * d;
    int yy = r.y + vy[v] * d;
    for (int j = 0; j < list.size(); j++) {
      if ((yy == r.y &&
           ((r.x <= list[j].x && list[j].x <= xx && list[j].y == yy) ||
            (xx <= list[j].x && list[j].x <= r.x && list[j].y == yy))) ||
          (xx == r.x &&
           ((r.y <= list[j].y && list[j].y <= yy && list[j].x == xx) ||
            (yy <= list[j].y && list[j].y <= r.y && list[j].x == xx)))) {
        use[j] = true;
      }
    }
    r.x = xx;
    r.y = yy;
  }
  for (int i = 0; i < use.size(); i++) {
    if (!use[i])
      return false;
  }
  return true;
}

int main() {
  while (input()) {
    if (solve()) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

struct P {
  int x, y;
};

vector<P> list;
int input() {
  int N;
  cin >> N;
  if (N == 0)
    return false;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    list.push_back(P{a, b});
  }
  return true;
}

int vx[] = {0, 1, 0, -1};
int vy[] = {1, 0, -1, 0};

bool solve() {
  int M;
  cin >> M;
  P r = P{10, 10};
  vector<int> use;
  use.resize(list.size());
  for (int i = 0; i < use.size(); i++) {
    use[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    char c;
    int d;
    cin >> c >> d;
    int v;
    switch (c) {
    case 'N':
      v = 0;
      break;
    case 'E':
      v = 1;
      break;
    case 'S':
      v = 2;
      break;
    case 'W':
      v = 3;
      break;
    }
    int xx = r.x + vx[v] * d;
    int yy = r.y + vy[v] * d;
    for (int j = 0; j < list.size(); j++) {
      if ((yy == r.y &&
           ((r.x <= list[j].x && list[j].x <= xx && list[j].y == yy) ||
            (xx <= list[j].x && list[j].x <= r.x && list[j].y == yy))) ||
          (xx == r.x &&
           ((r.y <= list[j].y && list[j].y <= yy && list[j].x == xx) ||
            (yy <= list[j].y && list[j].y <= r.y && list[j].x == xx)))) {
        use[i] = true;
      }
    }
    r.x = xx;
    r.y = yy;
  }
  for (int i = 0; i < use.size(); i++) {
    if (!use[i])
      return false;
  }
  return true;
}

int main() {
  while (input()) {
    if (solve()) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}