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

#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = (int)0; i < (int)n; i++)
#define llrep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define all(var) (var).begin(), (var).end()
#define prt(var) cout << var << endl
#define prt_dbl(i, var) cout << fixed << setprecision(i) << var << endl;

int main() {
  string S, ans, R, L;
  ans = "Yes";
  cin >> S;
  rep(i, (S.size() - 1) / 2) {
    R.push_back(S.at(i));
    L.push_back(S.at(1 + i + (S.size() - 1) / 2));
    if (S.at(i) != S.at(S.size() - 1 - i)) {
      ans = "No";
      cout << ans << endl;
      return 0;
    }
  }
  if (R.size() % 2 == 1) {
    rep(i, (R.size() - 1) / 2) {
      if (R.at(i) != R.at(R.size() - 1 - i)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
      if (L.at(i) != L.at(L.size() - 1 - i)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
    }
  } else {
    rep(i, (R.size()) / 2) {
      if (R.at(i) != R.at(R.size() - 1 - i)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
      if (L.at(i) != L.at(L.size() - 1 - i)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <map> // pair
using namespace std;

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = (int)0; i < (int)n; i++)
#define llrep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define REP(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define all(var) (var).begin(), (var).end()
#define prt(var) cout << var << endl
#define prt_dbl(i, var) cout << fixed << setprecision(i) << var << endl;

int main() {
  string S, ans, R, L;
  ans = "Yes";
  cin >> S;
  rep(i, (S.size() - 1) / 2) {
    R.push_back(S.at(i));
    L.push_back(S.at(1 + i + (S.size() - 1) / 2));
    if (S.at(i) != S.at(1 + i + (S.size() - 1) / 2)) {
      ans = "No";
      cout << ans << endl;
      return 0;
    }
  }
  if (R.size() % 2 == 1) {
    rep(i, (R.size() - 1) / 2) {
      if (R.at(i) != R.at(1 + i + (R.size() - 1) / 2)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
      if (L.at(i) != L.at(1 + i + (L.size() - 1) / 2)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
    }
  } else {
    rep(i, (R.size()) / 2) {
      if (R.at(i) != R.at(1 + i + (R.size()) / 2)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
      if (L.at(i) != L.at(1 + i + (L.size()) / 2)) {
        ans = "No";
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;
  return 0;
}