Problem p03865 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define clr(a, b) memset((a), (b), sizeof(a))
#define ctos(c) string(1, c)
#define print(x) cout << #x << " = " << x << endl;

#define MOD 1000000007

#define INF 10000000000LL

int f(string s, int c) {
  if (s.sz <= 2) {
    return 1 - c;
  }

  // 0
  if (c == 0) {
    int ret = 1;
    rep(i, 1, s.sz - 1) {
      if (s[i - 1] != s[i + 1]) {
        string s1;
        rep(j, 0, s.sz) {
          if (j == i)
            continue;
          s1 += s[j];
        }
        ret &= f(s1, 1 - c);
      }
    }
    return ret;
  }
  // 1
  else {
    int ret = 0;
    rep(i, 1, s.sz - 1) {
      if (s[i - 1] != s[i + 1]) {
        string s1;
        rep(j, 0, s.sz) {
          if (j == i)
            continue;
          s1 += s[j];
        }
        ret |= f(s1, 1 - c);
      }
    }
    return ret;
  }
}

unsigned int xor128(void) {
  static unsigned int x = 123456789;
  static unsigned int y = 362436069;
  static unsigned int z = 521288629;
  static unsigned int w = 88675123;
  unsigned int t;

  t = x ^ (x << 11);
  x = y;
  y = z;
  z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int f1(string s) {
  ll a = f(s, 0);
  ll b;
  if (s[0] == s[s.sz - 1]) {
    if (s.sz % 2 == 0) {
      b = 0;
      cout << "First" << endl;
    } else {
      b = 1;
      cout << "Second" << endl;
    }
  } else {
    if (s.sz % 2 == 1) {
      b = 0;
      cout << "First" << endl;
    } else {
      b = 1;
      cout << "Second" << endl;
    }
  }
  if (a == b) {
    return 1;
  } else {
    return 0;
  }
}

int main() {
  string s;
  cin >> s;
  string ss = "abcdefghijklmnopqrstuvwxyz";
  rep(i, 0, 1) {
    ll d = xor128() % 10 + 2;
    string s2;
    rep(i, 0, d) { s2 += ss[xor128() % 26]; }
    if (f1(s) == 1) {
      // cout << "fail" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define clr(a, b) memset((a), (b), sizeof(a))
#define ctos(c) string(1, c)
#define print(x) cout << #x << " = " << x << endl;

#define MOD 1000000007

#define INF 10000000000LL

int f(string s, int c) {
  if (s.sz <= 2) {
    return 1 - c;
  }

  // 0
  if (c == 0) {
    int ret = 1;
    rep(i, 1, s.sz - 1) {
      if (s[i - 1] != s[i + 1]) {
        string s1;
        rep(j, 0, s.sz) {
          if (j == i)
            continue;
          s1 += s[j];
        }
        ret &= f(s1, 1 - c);
      }
    }
    return ret;
  }
  // 1
  else {
    int ret = 0;
    rep(i, 1, s.sz - 1) {
      if (s[i - 1] != s[i + 1]) {
        string s1;
        rep(j, 0, s.sz) {
          if (j == i)
            continue;
          s1 += s[j];
        }
        ret |= f(s1, 1 - c);
      }
    }
    return ret;
  }
}

unsigned int xor128(void) {
  static unsigned int x = 123456789;
  static unsigned int y = 362436069;
  static unsigned int z = 521288629;
  static unsigned int w = 88675123;
  unsigned int t;

  t = x ^ (x << 11);
  x = y;
  y = z;
  z = w;
  return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

int f1(string s) {
  ll a = 0;
  ll b;
  if (s[0] == s[s.sz - 1]) {
    if (s.sz % 2 == 0) {
      b = 0;
      cout << "First" << endl;
    } else {
      b = 1;
      cout << "Second" << endl;
    }
  } else {
    if (s.sz % 2 == 1) {
      b = 0;
      cout << "First" << endl;
    } else {
      b = 1;
      cout << "Second" << endl;
    }
  }
  if (a == b) {
    return 1;
  } else {
    return 0;
  }
}

int main() {
  string s;
  cin >> s;
  string ss = "abcdefghijklmnopqrstuvwxyz";
  rep(i, 0, 1) {
    ll d = xor128() % 10 + 2;
    string s2;
    rep(i, 0, d) { s2 += ss[xor128() % 26]; }
    if (f1(s) == 1) {
      // cout << "fail" << endl;
    }
  }
  return 0;
}