Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v)                                                           \
  copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end());                       // 昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>());    // 降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int IINF = (1 << 30);
const ll LLINF = 1LL << 60;

int main() {
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  // cin.tie(0);
  // ios::sync_with_stdio(0);
  string s;
  cin >> s;
  vector<double> poRL;
  vector<double> poLR;
  rep_i(i, s.length() - 1) {
    if (s[i] == 'R' && s[i + 1] == 'L') {
      poRL.push_back(i);
    }
  }
  rep_i(i, s.length() - 1) {
    if (s[i] == 'L' && s[i + 1] == 'R') {
      poLR.push_back(i);
    }
  }
  vector<int> ans(s.length());
  if (poLR.empty()) {
    // R
    ans[int(poRL[0])] =
        round((poRL[0] + 1) / 2) + int(s.length() - poRL[0] - 1) / 2;
    // L
    ans[int(poRL[0] + 1)] =
        (int(poRL[0] + 1) - round((poRL[0] + 1) / 2)) +
        (int(s.length() - poRL[0] - 1) - int(s.length() - poRL[0] - 1) / 2);
    debug_vi(ans);
    cout << endl;
  } else {
    for (int i = 0; i < poRL.size(); i++) {
      if (i == 0) {
        // R
        ans[int(poRL[i])] =
            round((poRL[i] + 1) / 2) + int(poLR[0] - poRL[0]) / 2;
        // L
        ans[int(poRL[i] + 1)] =
            (int(poRL[i] + 1) - round((poRL[i] + 1) / 2)) +
            (int(poLR[0] - poRL[0]) - int(poLR[0] - poRL[0]) / 2);
      } else if (i == poRL.size() - 1) {
        // L
        ans[int(poRL[i] + 1)] = round((s.length() - (poRL[i] + 1)) / 2) +
                                int(poRL[i] - poLR[i - 1]) / 2;
        // R
        ans[int(poRL[i])] =
            ((s.length() - int(poRL[i] + 1)) -
             round((s.length() - (poRL[i] + 1)) / 2)) +
            (int(poRL[i] - poLR[i - 1]) - int(poRL[i] - poLR[i - 1]) / 2);
      } else {
        // R
        // if(i == 1){
        //   cout << round((poRL[i] - poLR[i - 1])/2) << endl;
        //   cout << int(poLR[i] - poRL[i])/2 << endl;
        // }
        ans[int(poRL[i])] =
            round((poRL[i] - poLR[i - 1]) / 2) + int(poLR[i] - poRL[i]) / 2;
        // L
        ans[int(poRL[i] + 1)] =
            (int(poRL[i] - poLR[i - 1]) - round((poRL[i] - poLR[i - 1]) / 2)) +
            (int(poLR[i] - poRL[i]) - int(poLR[i] - poRL[i]) / 2);
      }
    }
    debug_vi(ans);
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v)                                                           \
  copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v)                                                            \
  copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end());                       // 昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>());    // 降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); // 昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v) accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const int IINF = (1 << 30);
const ll LLINF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  vector<double> poRL;
  vector<double> poLR;
  rep_i(i, s.length() - 1) {
    if (s[i] == 'R' && s[i + 1] == 'L') {
      poRL.push_back(i);
    }
  }
  rep_i(i, s.length() - 1) {
    if (s[i] == 'L' && s[i + 1] == 'R') {
      poLR.push_back(i);
    }
  }
  vector<int> ans(s.length());
  if (poLR.empty()) {
    // R
    ans[int(poRL[0])] =
        round((poRL[0] + 1) / 2) + int(s.length() - poRL[0] - 1) / 2;
    // L
    ans[int(poRL[0] + 1)] =
        (int(poRL[0] + 1) - round((poRL[0] + 1) / 2)) +
        (int(s.length() - poRL[0] - 1) - int(s.length() - poRL[0] - 1) / 2);
    debug_vi(ans);
    cout << endl;
  } else {
    for (int i = 0; i < poRL.size(); i++) {
      if (i == 0) {
        // R
        ans[int(poRL[i])] =
            round((poRL[i] + 1) / 2) + int(poLR[0] - poRL[0]) / 2;
        // L
        ans[int(poRL[i] + 1)] =
            (int(poRL[i] + 1) - round((poRL[i] + 1) / 2)) +
            (int(poLR[0] - poRL[0]) - int(poLR[0] - poRL[0]) / 2);
      } else if (i == poRL.size() - 1) {
        // L
        ans[int(poRL[i] + 1)] = round((s.length() - (poRL[i] + 1)) / 2) +
                                int(poRL[i] - poLR[i - 1]) / 2;
        // R
        ans[int(poRL[i])] =
            ((s.length() - int(poRL[i] + 1)) -
             round((s.length() - (poRL[i] + 1)) / 2)) +
            (int(poRL[i] - poLR[i - 1]) - int(poRL[i] - poLR[i - 1]) / 2);
      } else {
        // R
        // if(i == 1){
        //   cout << round((poRL[i] - poLR[i - 1])/2) << endl;
        //   cout << int(poLR[i] - poRL[i])/2 << endl;
        // }
        ans[int(poRL[i])] =
            round((poRL[i] - poLR[i - 1]) / 2) + int(poLR[i] - poRL[i]) / 2;
        // L
        ans[int(poRL[i] + 1)] =
            (int(poRL[i] - poLR[i - 1]) - round((poRL[i] - poLR[i - 1]) / 2)) +
            (int(poLR[i] - poRL[i]) - int(poLR[i] - poRL[i]) / 2);
      }
    }
    debug_vi(ans);
    cout << endl;
  }
}