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

#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

// タロー→ハナァコォ

const int NONE = -1;

int main(void) {
  while (1) {
    int n;
    vector<int> card[2];
    cin >> n;
    if (n == 0)
      return 0;

    int field = NONE; // 今場に出ているカード
    int turn = 0;     // 0:太郎,1:花子;

    bool a[301] = {};
    for (int i = 0; i < n; ++i) {
      int t;
      cin >> t;
      card[0].push_back(t);
      a[t] = true;
    }

    for (int i = 1; i <= 2 * n; ++i) {
      if (a[i] == false)
        card[1].push_back(i);
    }

    sort(card[0].begin(), card[0].end());
    sort(card[1].begin(), card[1].end());

    while (1) {
      if (card[0].empty() || card[1].empty())
        break;
      if (field == NONE) {
        field = card[turn][0];
        card[turn].erase(card[turn].begin());
      } else {
        bool outFlag = false;
        for (int i = 0; i < card[turn].size(); ++i) {
          if (field < card[turn][i]) // 出せるカードがある
          {
            field = card[turn][i];
            outFlag = true;
            card[turn].erase(card[turn].begin() + i);
            break;
          }
        }
        if (outFlag == false) {
          field = NONE;
        }
      }
      if (turn == 0)
        turn = 1;
      else if (turn == 1)
        turn = 0;
    }
    int tsum = 0;
    int hsum = 0;
    for (int i = 0; i < card[0].size(); ++i) {
      hsum += card[0][i];
    }
    for (int j = 0; j < card[1].size(); ++j) {
      tsum += card[1][j];
    }
    cout << card[1].size() << endl;
    cout << card[0].size() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; ++i)

using namespace std;

// タロー→ハナァコォ

const int NONE = -1;

int main(void) {
  while (1) {
    int n;
    vector<int> card[2];
    cin >> n;
    if (n == 0)
      return 0;

    int field = NONE; // 今場に出ているカード
    int turn = 0;     // 0:太郎,1:花子;

    bool a[301] = {};
    for (int i = 0; i < n; ++i) {
      int t;
      cin >> t;
      card[0].push_back(t);
      a[t] = true;
    }

    for (int i = 1; i <= 2 * n; ++i) {
      if (a[i] == false)
        card[1].push_back(i);
    }

    sort(card[0].begin(), card[0].end());
    sort(card[1].begin(), card[1].end());

    while (1) {
      if (card[0].empty() || card[0].empty())
        break;
      if (field == NONE) {
        field = card[turn][0];
        card[turn].erase(card[turn].begin());
      } else {
        bool outFlag = false;
        for (int i = 0; i < card[turn].size(); ++i) {
          if (field < card[turn][i]) // 出せるカードがある
          {
            field = card[turn][i];
            outFlag = true;
            card[turn].erase(card[turn].begin() + i);
            break;
          }
        }
        if (outFlag == false) {
          field = NONE;
        }
      }
      if (turn == 0)
        turn = 1;
      else if (turn == 1)
        turn = 0;
    }
    int tsum = 0;
    int hsum = 0;
    for (int i = 0; i < card[0].size(); ++i) {
      hsum += card[0][i];
    }
    for (int j = 0; j < card[1].size(); ++j) {
      tsum += card[1][j];
    }
    cout << card[1].size() << endl;
    cout << card[0].size() << endl;
  }
  return 0;
}