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

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

#define int long long
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define deb(x) cerr << "[" << #x << " : " << x << "]\\n";
#define debb(x, y)                                                             \\
  cerr << "\\t[" << #x << " : " << x << ", " << #y << " : " << y << "]\\n";
#define debv(v)                                                                \\
  {                                                                            \\
    cerr << #v << " : ";                                                       \\
    for (auto x : v)                                                           \\
      cerr << x << ' ';                                                        \\
    cerr << "\\n";                                                              \\
  }
#define pb push_back
#define pp pop_back
#define mkp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define MAX 50000

typedef long double ld;
const int N = 1e5 + 10;
const int maxn = 2e6 + 10;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < (int)s.size();) {
    if (s[i] == 'R') {
      int cnt = 0;
      while (i < (int)s.size() && s[i] == 'R') {
        i++;
        cnt++;
      }
      ans = max(ans, cnt);
    } else {
      i++;
    }
  }

  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

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

#define int long long
#define test                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define deb(x) cerr << "[" << #x << " : " << x << "]\\n";
#define debb(x, y)                                                             \\
  cerr << "\\t[" << #x << " : " << x << ", " << #y << " : " << y << "]\\n";
#define debv(v)                                                                \\
  {                                                                            \\
    cerr << #v << " : ";                                                       \\
    for (auto x : v)                                                           \\
      cerr << x << ' ';                                                        \\
    cerr << "\\n";                                                              \\
  }
#define pb push_back
#define pp pop_back
#define mkp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define MAX 50000

typedef long double ld;
const int N = 1e5 + 10;
const int maxn = 2e6 + 10;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string s;
  cin >> s;

  int ans = 0;
  for (int i = 0; i < (int)s.size();) {
    if (s[i] == 'R') {
      while (i < (int)s.size() && s[i] == 'R') {
        ans++;
      }
    } else {
      i++;
    }
  }

  cout << ans;
  return 0;
}