Problem p02730 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize("-O3")
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for (li i = j; i < k; i += in)
#define RFOR(i, j, k, de) for (li i = j; i >= k; i -= de)
#define rep(i, j, k) FOR(i, j, k, 1)
#define rrep(i, j, k) RFOR(i, j, k, 1)
#define repc(v) for (auto it = v.begin(); it != v.end(); it++)
#define T                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

int main() {
  FAST

      string s;
  cin >> s;
  int l = s.length();

  int f = 0;
  int i = 0, j = l - 1;
  while (i < j) {
    if (s[i] != s[j]) {
      f = 1;
      break;
    }
    i++;
    j--;
  }

  if (f == 0) {
    int a = (l - 1) / 2;
    int b = (l + 3) / 2 - 1;

    int f1 = 0, f2 = 0;
    i = 0, j = a - 1;
    while (i < j) {
      if (s[i] != s[j]) {
        f1 = 1;
        break;
      }
      i++;
      j--;
    }

    i = b, j = l - 1;
    while (i < j) {
      if (s[i] != s[j]) {
        f2 = 1;
        break;
      }
      i++;
      j--;
    }

    if (f1 == 0 && f2 == 0)
      cout << "Yes";
    else
      cout << "No";
  }

  else
    cout << "No";

  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;

#pragma GCC optimize("-O3")
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define PI 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define all(v) v.begin(), v.end()
#define FOR(i, j, k, in) for (li i = j; i < k; i += in)
#define RFOR(i, j, k, de) for (li i = j; i >= k; i -= de)
#define rep(i, j, k) FOR(i, j, k, 1)
#define rrep(i, j, k) RFOR(i, j, k, 1)
#define repc(v) for (auto it = v.begin(); it != v.end(); it++)
#define T                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

int main() {
  FAST

      string s;
  cin >> s;
  int l = s.length();

  int f = 0;
  int i = 0, j = l - 1;
  while (i < j) {
    if (s[i] != s[j]) {
      f = 1;
      break;
    }
  }

  if (f == 0) {
    int a = (l - 1) / 2;
    int b = (l + 3) / 2 - 1;

    int f1 = 0, f2 = 0;
    i = 0, j = a - 1;
    while (i < j) {
      if (s[i] != s[j]) {
        f1 = 1;
        break;
      }
    }

    i = b, j = l - 1;
    while (i < j) {
      if (s[i] != s[j]) {
        f2 = 1;
        break;
      }
    }

    if (f1 == 0 && f2 == 0)
      cout << "Yes";
    else
      cout << "No";
  }

  else
    cout << "No";

  return 0;
}