Problem p02582 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define mod 1000000007
#define inf 9223372036854775807
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define umap unordered_map<ll, ll>
#define lpq priority_queue<ll, vector<ll>, greater<ll>>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repr(i, a, n) for (ll i = n - 1; i >= a; i--)
ll globe = 0;
template <typename TN> void sorted(TN &v) { sort(v.begin(), v.end()); }
template <typename TN> void reversed(TN &v) { reverse(v.begin(), v.end()); }
ll powe(ll n, ll r) {
  if (!r)
    return 1;
  else if (r % 2 == 0)
    return powe(n * n, r / 2);
  else
    return n * powe(n * n, (r - 1) / 2);
}
void traverseVLL(vll &arr, ll a, ll b) {
  rep(i, a, b) cout << arr[i] << " ";
  cout << endl;
}
void traverseVPLL(vector<pll> &v, ll a, ll b) {
  rep(i, a, b) { cout << v[i].F << " " << v[i].S << endl; }
}
void traverseVVLL(vector<vll> &v) {
  rep(i, 0, v.size()) {
    rep(j, 0, v[i].size()) { cout << v[i][j] << " "; }
    cout << endl;
  }
}
void init(vll &v, ll a, ll b) {
  for (ll i = a; i < b; i++)
    cin >> v[i];
}
ll sqr(ll r) { return r * r; }

void solution() {
  ll cnt = 0;
  string s;
  cin >> s;
  vll v;
  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'R')
      cnt++;
    else {
      v.pb(cnt);
      cnt = 0;
    }
  }
  if (s[s.size() - 1] == 'R')
    v.pb(cnt);
  sort(v.begin(), v.end());
  cout << v[v.size() - 1] << endl;
}

int main() {
  /*
  #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      #endif*/

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

  ll T = 1;
  // cin>>T;
  while (T--) {
    solution();
  }

  return 0;
}

// BitMasking->setBit: n|(1<<i); unsetBit: n&!(1<<i); checkBit: n&(1<<i);
// ll idcharacter=upper_bound(v.begin(),v.end(),val)-v.begin();
// v.erase(unique(v.begin(),v.end()),v.end());
// ll cnt=count(v.begin(),v.end(),val);
// bool f=find(v.begin(),v.end(),val);

Error: 0

Fixed submission:

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

#define ll long long
#define mod 1000000007
#define inf 9223372036854775807
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define umap unordered_map<ll, ll>
#define lpq priority_queue<ll, vector<ll>, greater<ll>>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repr(i, a, n) for (ll i = n - 1; i >= a; i--)
ll globe = 0;
template <typename TN> void sorted(TN &v) { sort(v.begin(), v.end()); }
template <typename TN> void reversed(TN &v) { reverse(v.begin(), v.end()); }
ll powe(ll n, ll r) {
  if (!r)
    return 1;
  else if (r % 2 == 0)
    return powe(n * n, r / 2);
  else
    return n * powe(n * n, (r - 1) / 2);
}
void traverseVLL(vll &arr, ll a, ll b) {
  rep(i, a, b) cout << arr[i] << " ";
  cout << endl;
}
void traverseVPLL(vector<pll> &v, ll a, ll b) {
  rep(i, a, b) { cout << v[i].F << " " << v[i].S << endl; }
}
void traverseVVLL(vector<vll> &v) {
  rep(i, 0, v.size()) {
    rep(j, 0, v[i].size()) { cout << v[i][j] << " "; }
    cout << endl;
  }
}
void init(vll &v, ll a, ll b) {
  for (ll i = a; i < b; i++)
    cin >> v[i];
}
ll sqr(ll r) { return r * r; }

void solution() {
  ll cnt = 0;
  string s;
  cin >> s;
  vll v;
  for (ll i = 0; i < 3; i++) {
    if (s[i] == 'R')
      cnt++;
    else {
      v.pb(cnt);
      cnt = 0;
    }
  }
  sort(v.begin(), v.end());
  cout << v[v.size() - 1] << endl;
}

int main() {
  /*
  #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      #endif*/

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

  ll T = 1;
  // cin>>T;
  while (T--) {
    solution();
  }

  return 0;
}

// BitMasking->setBit: n|(1<<i); unsetBit: n&!(1<<i); checkBit: n&(1<<i);
// ll idcharacter=upper_bound(v.begin(),v.end(),val)-v.begin();
// v.erase(unique(v.begin(),v.end()),v.end());
// ll cnt=count(v.begin(),v.end(),val);
// bool f=find(v.begin(),v.end(),val);