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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\\n'
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define tc                                                                     \\
  int tc;                                                                      \\
  cin >> tc;                                                                   \\
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
bool comp(pair<int, int> v, int val) { return v.ff < val; }
inline int read() {
  int t = 0;
  char c;
  while ((c = getchar_unlocked()) != '\\n' && c != ' ' && c != EOF) {
    t = t * 10 + c - 48;
  }
  return t;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  string S;
  cin >> S;
  int i = 1;
  int ans = 0;
  if (S == "RSR" || S == "RSS" || S == "SSR" || S == "SRS")
    cout << 1;
  else if (S == "RRR")
    cout << 3;
  else if (S == "RRS" || S == "SRR")
    cout << 2;
  else
    cout << 0;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\\n'
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define tc                                                                     \\
  int tc;                                                                      \\
  cin >> tc;                                                                   \\
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
bool comp(pair<int, int> v, int val) { return v.ff < val; }
inline int read() {
  int t = 0;
  char c;
  while ((c = getchar_unlocked()) != '\\n' && c != ' ' && c != EOF) {
    t = t * 10 + c - 48;
  }
  return t;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  string S;
  cin >> S;
  int i = 1;
  int ans = 0;
  while (i < SZ(S)) {
    if (S[i] == 'R' && S[i - 1] == 'R')
      ans++;
  }
  cout << ans;
  return 0;
}