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

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \\
  if (flg) {                                                                   \\
    cout << "YES" << endl;                                                     \\
  } else {                                                                     \\
    cout << "NO" << endl;                                                      \\
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 100000000000000001;
struct edge {
  int to, cost;
};
struct pos {
  int x, y, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

int f[200002] = {};
ll d[200002] = {};
ll d2[200002] = {};
int main() {

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

  ll t = 0;
  rep(i, s.size()) {
    if (s[i] == 'x')
      f[i] = 1;
    d[i] = d[i - 1];
    if (d[i] == k || s[i] == 'x')
      continue;
    if (t > i)
      f[i] = 1;
    else {
      d[i]++;
      t = i + c + 1;
    }
  }

  ll t2 = s.size();
  rrep(i, s.size()) {
    d2[i] = d2[i + 1];
    if (d2[i] == k || s[i] == 'x')
      continue;
    if (t2 < i)
      f[i] = 1;
    else {
      d2[i]++;
      t2 = i - c - 1;
    }
  }
  if (d2[1] < k)
    cout << "1" << endl;
  rep(i, s.size() - 1) {
    if (d[i] + d2[i + 2] < k && f[i + 1] == 0)
      cout << i + 2 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define yesno(flg)                                                             \\
  if (flg) {                                                                   \\
    cout << "YES" << endl;                                                     \\
  } else {                                                                     \\
    cout << "NO" << endl;                                                      \\
  }
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P1;
typedef pair<int, int> Pi;
typedef pair<double, Pi> Pdi;
typedef pair<ll, int> Pli;
typedef pair<P1, ll> P2;
const ll INF = 100000000000000001;
struct edge {
  int to, cost;
};
struct pos {
  int x, y, cost;
};
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
struct Road {
  double cost;
  int a, b;
};

int f[200002] = {};
ll d[200002] = {};
ll d2[200002] = {};
int main() {

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

  ll t = 0;
  rep(i, s.size()) {
    if (s[i] == 'x')
      f[i] = 1;
    d[i] = d[i - 1];
    if (d[i] == k || s[i] == 'x')
      continue;
    if (t > i)
      f[i] = 1;
    else {
      d[i]++;
      t = i + c + 1;
    }
  }

  ll t2 = s.size();
  rrep(i, s.size()) {
    d2[i] = d2[i + 1];
    if (d2[i] == k || s[i] == 'x')
      continue;
    if (t2 < i)
      f[i] = 1;
    else {
      d2[i]++;
      t2 = i - c - 1;
    }
  }
  if (d2[1] < k)
    cout << "1" << endl;
  rep(i, s.size() - 2) {
    if (d[i] + d2[i + 2] < k && f[i + 1] == 0)
      cout << i + 2 << endl;
  }
  if (d[s.size() - 2] < k)
    cout << s.size() << endl;
  return 0;
}