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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int, int>
#define pl pair<ll, ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout << "Case " << cas << ": "
#define _ continue;
#define endl '\\n'
#define __                                                                     \\
  cout << endl;                                                                \\
  continue;
#define vc4d(nam, type, a, b, c, d, fix)                                       \\
  vector<vector<vector<vector<type>>>> nam(                                    \\
      a, vector<vector<vector<type>>>(                                         \\
             b, vector<vector<type>>(c, vector<type>(d, fix))))
const ll oo = (1ll << 60);

int main() {
  io;
  int T = 1;
  // cin>>T;
  // for(int cas=1;cas<=T;cas++)
  while (T--) {
    string s;
    int cnt = 0, ans = 0, i;
    cin >> s;
    for (i = 0; i < 3; i++) {
      if (s[i] == 'R') {
        cnt = 0;
        while (i < 3 and s[i] == 'R')
          cnt++, i++;
        ans = max(cnt, ans);
      }
    }
    cout << ans;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define uu unsigned
#define io                                                                     \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define MOD 1000000007
#define pi pair<int, int>
#define pl pair<ll, ll>
#define mkp make_pair
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define pf push_front
#define printcas cout << "Case " << cas << ": "
#define _ continue;
#define endl '\\n'
#define __                                                                     \\
  cout << endl;                                                                \\
  continue;
#define vc4d(nam, type, a, b, c, d, fix)                                       \\
  vector<vector<vector<vector<type>>>> nam(                                    \\
      a, vector<vector<vector<type>>>(                                         \\
             b, vector<vector<type>>(c, vector<type>(d, fix))))
const ll oo = (1ll << 60);

int main() {
  io;
  int T = 1;
  // cin>>T;
  // for(int cas=1;cas<=T;cas++)
  while (T--) {
    string s;
    int cnt = 0, ans = 0, i;
    cin >> s;
    for (i = 0; i < 3; i++) {
      if (s[i] == 'R') {
        cnt = 0;
        while (i < 3 and s[i] == 'R')
          cnt++;
        ans = max(cnt, ans);
      }
    }
    cout << ans;
  }
  return 0;
}