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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  nl
#define ov(a)                                                                  \\
  for (int i = 0; i < a.size(); i++)                                           \\
    cout << a[i] + 1 << " ";                                                   \\
  nl
#define vinn(n, v)                                                             \\
  int n;                                                                       \\
  cin >> n;                                                                    \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define vinm(n, m, v)                                                          \\
  int n, m;                                                                    \\
  cin >> n >> m;                                                               \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define debug(x) cerr << #x << " : " << x << endl;
mt19937 rd(time(0)); // i = rd%n
signed main() {
  fastio();

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  vector<int> fr, zr;
  for (int i = 0; i < n; i++) {
    if (cnt == k)
      break;
    if (s[i] == 'o')
      fr.pb(i), i += c, cnt++;
  }
  cnt = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (cnt == k)
      break;
    if (s[i] == 'o')
      zr.pb(i), i -= c, cnt++;
  }
  reverse(all(zr));
  for (int i = 0; i < k; i++)
    if (zr[i] == fr[i])
      cout << fr[i] + 1 << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define test()                                                                 \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pb push_back
#define nl cout << endl
#define MOD 1000000007
#define loop(i, start, end) for (int i = start; i < end; i++)
#define N 100001
#define all(v) v.begin(), v.end()
#define oa(a, n)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";                                                       \\
  nl
#define ov(a)                                                                  \\
  for (int i = 0; i < a.size(); i++)                                           \\
    cout << a[i] + 1 << " ";                                                   \\
  nl
#define vinn(n, v)                                                             \\
  int n;                                                                       \\
  cin >> n;                                                                    \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define vinm(n, m, v)                                                          \\
  int n, m;                                                                    \\
  cin >> n >> m;                                                               \\
  vector<int> v(n);                                                            \\
  loop(i, 0, n) cin >> v[i];
#define debug(x) cerr << #x << " : " << x << endl;
mt19937 rd(time(0)); // i = rd%n
signed main() {
  fastio();
  int n, k, c, te;
  cin >> n >> k >> c;
  string s;
  te = k;
  cin >> s;
  int ans = 0;
  vector<int> fr, zr;
  for (int i = 0; i < n; i++) {
    if (k == 0)
      break;
    if (s[i] == 'o')
      fr.pb(i), i += c, k--;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (te == 0)
      break;
    if (s[i] == 'o')
      zr.pb(i), i -= c, te--;
  }
  reverse(all(zr));
  for (int i = 0; i < n; i++)
    if (zr[i] == fr[i] && zr[i] != 0)
      cout << fr[i] + 1 << endl;

  return 0;
}