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

#include <bits/stdc++.h>
using namespace std;

typedef long long
    ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

// #define DEBUG

void solve(long long N, long long K, long long C, std::string S) {
  vec<pair<ll, ll>> kokomade;
  vec<pair<ll, ll>> kokokara;

  // kokomadeをつくる
  ll disabled = -1;
  ll num = 0;
  for (int i = 0; i < N; i++) {
    if (i <= disabled) {
      kokomade.push_back(pair<ll, ll>(num, disabled));
      continue;
    }
    if (S[i] == 'o') {
      num++;
      disabled = i + C;
      kokomade.push_back(pair<ll, ll>(num, disabled));
    } else {
      kokomade.push_back(pair<ll, ll>(num, disabled));
    }
  }
#ifdef DEBUG
  printf("*START: kokomade\\n");
  for (auto iter : kokomade) {
    printf("(%d, %d), ", iter.first, iter.second);
  }
  printf("\\n");
  printf("*END: kokomade\\n");
#endif

  disabled = N;
  num = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i >= disabled) {
      kokokara.push_back(pair<ll, ll>(num, disabled));
      continue;
    }
    if (S[i] == 'o') {
      num++;
      disabled = i - C;
      kokokara.push_back(pair<ll, ll>(num, disabled));
    } else {
      kokokara.push_back(pair<ll, ll>(num, disabled));
    }
  }
  reverse(kokokara.begin(), kokokara.end());
#ifdef DEBUG
  printf("*START: kokokara\\n");
  for (auto iter : kokokara) {
    printf("(%d, %d), ", iter.first, iter.second);
  }
  printf("\\n");
  printf("*END: kokokara\\n");
#endif

  if (N == 1) {
    cout << 1 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      if (S[i] == 'x') {
        continue;
      }
      if (i == 0) {
        if (kokokara.at(1).first < K) {
          cout << i + 1 << endl;
        }
      } else {
        auto made = kokomade.at(i - 1);
        auto karaId = max((ll)(i + 1), made.second + 1);
        auto kara = (karaId < kokokara.size() ? kokokara.at(karaId)
                                              : pair<ll, ll>(0, 0));
        if (made.first + kara.first < K) {
          cout << i + 1 << endl;
        }
      }
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  long long C;
  scanf("%lld", &C);
  std::string S;
  std::cin >> S;
  solve(N, K, C, S);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long
    ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

// #define DEBUG

void solve(long long N, long long K, long long C, std::string S) {
  vec<pair<ll, ll>> kokomade;
  vec<pair<ll, ll>> kokokara;

  // kokomadeをつくる
  ll disabled = -1;
  ll num = 0;
  for (int i = 0; i < N; i++) {
    if (i <= disabled) {
      kokomade.push_back(pair<ll, ll>(num, disabled));
      continue;
    }
    if (S[i] == 'o') {
      num++;
      disabled = i + C;
      kokomade.push_back(pair<ll, ll>(num, disabled));
    } else {
      kokomade.push_back(pair<ll, ll>(num, disabled));
    }
  }
#ifdef DEBUG
  printf("*START: kokomade\\n");
  for (auto iter : kokomade) {
    printf("(%d, %d), ", iter.first, iter.second);
  }
  printf("\\n");
  printf("*END: kokomade\\n");
#endif

  disabled = N;
  num = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (i >= disabled) {
      kokokara.push_back(pair<ll, ll>(num, disabled));
      continue;
    }
    if (S[i] == 'o') {
      num++;
      disabled = i - C;
      kokokara.push_back(pair<ll, ll>(num, disabled));
    } else {
      kokokara.push_back(pair<ll, ll>(num, disabled));
    }
  }
  reverse(kokokara.begin(), kokokara.end());
#ifdef DEBUG
  printf("*START: kokokara\\n");
  for (auto iter : kokokara) {
    printf("(%d, %d), ", iter.first, iter.second);
  }
  printf("\\n");
  printf("*END: kokokara\\n");
#endif

  for (int i = 0; i < N; i++) {
    if (S[i] == 'x') {
      continue;
    }
    if (i == 0) {
      if (kokokara.at(1).first < K) {
        cout << i + 1 << endl;
      }
    } else {
      auto made = kokomade.at(i - 1);
      auto karaId = max((ll)(i + 1), made.second + 1);
      auto kara =
          (karaId < kokokara.size() ? kokokara.at(karaId) : pair<ll, ll>(0, 0));
      if (made.first + kara.first < K) {
        cout << i + 1 << endl;
      }
    }
  }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  long long C;
  scanf("%lld", &C);
  std::string S;
  std::cin >> S;
  solve(N, K, C, S);
  return 0;
}