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

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define lowbit(x) x & -x
#define pb push_back
#define ls (id << 1)
#define rs (id << 1 | 1)
#define Rint register int
#define UNI(x) sort(ALL(x)), x.resize(unique(ALL(x)) - x.begin())
#define GETPOS(c, x) (lower_bound(ALL(c), x) - c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x), 0, sizeof((x)))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
  _W(x.F);
  putchar(' ');
  _W(x.S);
}
template <class T> void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin())
      putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\\n');
  W(tail...);
}
const int MAXN = 1e6 + 10, MAXM = 4e6 + 10;
const int INF = INT_MAX, SINF = 0x3f3f3f3f;
const ll llINF = LLONG_MAX;
const int MOD = 1e9 + 7, mod = 998244353;
const int inv2 = 5e8 + 4;
const int Lim = 1 << 20;

int n, k, c;
char s[MAXN];
int cnt[MAXN];
Vi ans;

void solve() {
  R(n, k, c, s);
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      cnt[i]++;
      i = i + c;
      res++;
    }
  }
  if (res > k)
    return;
  for (int i = n - 1; i > -1; i--) {
    if (s[i] == 'o') {
      cnt[i]++;
      i = i - c;
      res++;
    }
  }
  for (int i = 0; i < n; i++)
    if (cnt[i] == 2)
      W(i + 1);
}

int main() {
  int t = 1;
  // R(t);
  while (t--)
    solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define lowbit(x) ((x) & (-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x) * (x))
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
typedef long long ll;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
using namespace std;
char s[maxn];
int l[maxn], r[maxn];
int main(void) {
#ifdef ljxtt
  freopen("data.in", "r", stdin);
#endif
  int n, k, c;
  scanf("%d%d%d%s", &n, &k, &c, s + 1);
  for (int i = 1, m = 0, next = 0; i <= n && m < k; i++) {
    if (i > next && s[i] != 'x') {
      l[m++] = i;
      next = i + c;
    }
  }
  for (int i = n, m = k - 1, next = n + 1; i >= 1 && m >= 0; i--) {
    if (i < next && s[i] != 'x') {
      r[m--] = i;
      next = i - c;
    }
  }
  for (int i = 0; i < k; i++) {
    // printf("%d %d\\n", l[i], r[i]);
    if (l[i] == r[i] && l[i] != 0)
      printf("%d\\n", l[i]);
  }
  return 0;
}