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

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cint                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define N 10005
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
int mod = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
int powmod(int a, int b) {
  int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int32_t main() {
  faster;

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  int l[k], r[k];
  for (int i = 0; i < k; i++) {
    l[i] = -1;
    r[i] = -2;
  }

  int j = 0;

  for (int i = 0; i < s.length() && j < k; i++) {
    if (s[i] == 'o') {
      l[j] = i;
      j++;
      i += c;
    }
  }

  j = k - 1;

  for (int i = s.length() - 1; i >= 0 && j >= 0; i--) {
    if (s[i] == 'o') {
      r[j] = i;
      j--;
      i -= c;
    }
  }

  for (int i = 0; i < k; i++) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cint                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define N 10005
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
int mod = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
int powmod(int a, int b) {
  int res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int32_t main() {
  faster;

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  int l[k], r[k];
  int j = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'o') {
      l[j] = i;
      j++;
      i += c;
      //            i--;
    }
  }
  j = k - 1;
  //    reverse(s.begin(),s.end());
  for (int i = s.length() - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      r[j] = i;
      j--;
      i -= c;
      //            i++;
    }
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
  //    cout<<endl;
}