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

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i)
#define all(x) begin(x), end(x)
using namespace std;
const int INF = 1e9;
template <class T = int> using V = vector<T>;
template <class T = int> using PQ = priority_queue<T>;
template <class T = int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9 + 7LL;
void in() {}
template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) {
  cin >> head;
  in(move(tail)...);
}
#define IN(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
// 時間が厳しいとき使う
#define INI(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define INS(T, ...)                                                            \\
  T __VA_ARGS__;                                                               \\
  in(__VA_ARGS__)
#define VIN(T, v, n)                                                           \\
  V<T> v(n);                                                                   \\
  for (auto &_elem : v)                                                        \\
  cin >> _elem
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

bool a[200005] = {};
bool b[200005] = {};

void solve() {
  IN(n, k, c);
  string s;
  cin >> s;
  ll i = 0;
  ll count = 0;
  while (i < n) {
    if (i >= n)
      break;
    if (s[i] == 'x') {
      ++i;
      continue;
    }
    a[i] = 1;
    ++count;
    i += c + 1;
  }
  if (count != k) {
    return;
  }
  i = n - 1;
  while (i >= 0) {
    if (i < 0)
      break;
    if (s[i] == 'x') {
      --i;
      continue;
    }
    b[i] = 1;
    i -= c + 1;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] && b[i])
      cout << i + 1 << endl;
  }
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(numeric_limits<double>::max_digits10);

  solve();

  return 0;
}

Error: 0

Fixed submission:

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i)
#define all(x) begin(x), end(x)
using namespace std;
const int INF = 1e9;
template <class T = int> using V = vector<T>;
template <class T = int> using PQ = priority_queue<T>;
template <class T = int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9 + 7LL;
void in() {}
template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) {
  cin >> head;
  in(move(tail)...);
}
#define IN(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
// 時間が厳しいとき使う
#define INI(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define INS(T, ...)                                                            \\
  T __VA_ARGS__;                                                               \\
  in(__VA_ARGS__)
#define VIN(T, v, n)                                                           \\
  V<T> v(n);                                                                   \\
  for (auto &_elem : v)                                                        \\
  cin >> _elem
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

bool a[20005] = {};
bool b[20005] = {};

void solve() {
  IN(n, k, c);
  string s;
  cin >> s;
  int i = 0;
  ll count = 0;
  while (i < n) {
    if (i >= n)
      break;
    if (s[i] == 'x') {
      ++i;
      continue;
    }
    a[i] = 1;
    ++count;
    i += c + 1;
  }
  if (count != k) {
    return;
  }
  i = n - 1;
  while (i >= 0) {
    if (i < 0)
      break;
    if (s[i] == 'x') {
      --i;
      continue;
    }
    b[i] = 1;
    i -= c + 1;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] && b[i])
      cout << i + 1 << endl;
  }
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(numeric_limits<double>::max_digits10);

  solve();

  return 0;
}