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

// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {

  while (1) {
    int n;
    int p;
    int result = -1;

    cin >> n;
    if (n == 0) {
      break;
    }
    vector<string> s(n);
    FOR(i, 0, n - 1) { cin >> s[i]; }

    FOR(k, 1, 50) {
      // cout << k << endl;
      vector<string> t(n);
      FOR(i, 0, n - 1) {
        t[i].push_back(s[i][0]);
        if (t[i].size() >= k) {
          continue;
        }
        p = s[i].size() - 2;
        FOR(j, 0, p) {
          // cout << i << " " << j << " " << p << endl;
          switch (s[i][j]) {
          case 'a':
          case 'i':
          case 'u':
          case 'e':
          case 'o':
            t[i].push_back(s[i][j + 1]);
            break;
          }
          if (t[i].size() >= k) {
            break;
            ;
          }
        }
      }
      sort(t.begin(), t.end());
      FOR(i, 0, n - 2) {
        if (t[i] == t[i + 1]) {
          break;
        }
        if (i == n - 2) {
          result = k;
        }
      }
      if (result != -1) {
        break;
      }
    }

    cout << result << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000            // 2000000000
#define LLINF 1000000000000000000 // 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int main(void) {

  while (1) {
    int n;
    int result = -1;

    cin >> n;
    if (n == 0) {
      break;
    }
    vector<string> s(n);
    FOR(i, 0, n - 1) { cin >> s[i]; }

    FOR(k, 1, 50) {
      vector<string> t(n);
      FOR(i, 0, n - 1) {
        t[i].push_back(s[i][0]);
        if (t[i].size() >= k) {
          continue;
        }
        FOR(j, 0, s[i].size() - 2) {
          switch (s[i][j]) {
          case 'a':
          case 'i':
          case 'u':
          case 'e':
          case 'o':
            t[i].push_back(s[i][j + 1]);
            break;
          }
          if (t[i].size() >= k) {
            break;
            ;
          }
        }
      }
      sort(t.begin(), t.end());
      FOR(i, 0, n - 2) {
        if (t[i] == t[i + 1]) {
          break;
        }
        if (i == n - 2) {
          result = k;
        }
      }
      if (result != -1) {
        break;
      }
    }

    cout << result << endl;
  }

  return 0;
}