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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstring>
#include <deque> // deque
#include <float.h>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
int my_gcd(int n, int m) {
  if (n < m) {
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l = n % m;
  while (l != 0) {
    n = m;
    m = l;
    l = n % m;
  }
  return m;
}

// char⇒int関数
int ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<char> A(50), B(50);
  rep(i, N / 2) {
    A[i] = S[i];
    B[i] = S[i + (N / 2) + 1];
  }
  bool ans = true;
  rep(i, N / 2) {
    if (S[i] != S[N - i - 1]) {
      ans = false;
    }
  }
  rep(i, N / 2) {
    if (A[i] == S[N / 2 - i - 1] && B[i] == S[N - i - 1]) {
    } else
      ans = false;
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Error: 0

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <cstring>
#include <deque> // deque
#include <float.h>
#include <iostream> // cout, endl, cin
#include <map>      // map
#include <numeric>
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
int my_gcd(int n, int m) {
  if (n < m) {
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l = n % m;
  while (l != 0) {
    n = m;
    m = l;
    l = n % m;
  }
  return m;
}

// char⇒int関数
int ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<char> A(50, '#'), B(50, '#');
  rep(i, N / 2) {
    A[i] = S[i];
    B[i + (N / 2) + 1] = S[i + (N / 2) + 1];
  }
  bool ans = true;
  rep(i, N / 2) {
    if (A[i] == S[N / 2 - i - 1] && B[i + 1 + (N / 2)] == S[N - i - 1]) {
    } else
      ans = false;
  }
  if (ans)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}