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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> hidari(n + 2, 0);
  vector<int> migi(n + c + 3, 0);

  for (int i = 1; i <= n; ++i) {
    if (s[i - 1] == 'x') {
      hidari[i] = hidari[i - 1];
    } else {
      if (i - c - 1 <= 0) {
        hidari[i] = 1;
      } else {
        hidari[i] = hidari[i - c - 1] + 1;
      }
    }
  }

  vector<int> in(n + 2, 0);
  vector<int> out(n + c + 2, 0);

  for (int i = n + 1; i > 0; --i) {
    if (i - 1 >= n) {
      migi[i] = 0;
    } else if (s[i - 1] == 'x') {
      if (i + 1 <= n)
        migi[i] = migi[i + 1];
    } else {
      if (i + 1 + c > n)
        migi[i] = 1;
      else {
        migi[i] = migi[i + 1 + c] + 1;
      }
    }

    /*
    int temp = migi[i];
    if(i-c-1>=0){
        temp +=hidari[i-c-1];
    }
    if(temp>=k){
        cout << "i: "<<i<<endl;
        out[i]+=1;
        if(i-c>=0) in[i-c]+=1;
        else in[0]+=1;
    }*/
  }

  if (c == 0) {
    if (hidari[n] > k) {
      return 0;
    } else {
      rep(i, n) {
        if (s[i] == 'o')
          cout << i + 1 << endl;
      }
    }
    return 0;
  }

  for (int r = 1; r <= (n + c + 1); ++r) {
    int temp = migi[r];
    if (r - c - 1 >= 0) {
      temp += hidari[r - c - 1];
    }
    if (temp >= k) {
      out[r] += 1;
      if (r - c >= 0) {
        in[r - c] += 1;
      } else
        in[0] += 1;
    }
  }

  /*
  for(auto h:hidari){
      cout << h << " ";
  }
  cout << endl;
  for(auto m:migi){
      cout << m << " ";
  }
  cout << endl;
  */
  int temp = 0;
  rep(i, n + 1) {
    temp += in[i];
    temp -= out[i];
    // cout <<"i: "<< i <<"t:" <<temp << endl;
    if (temp >= 1) {
      continue;
    }

    if (i == 0)
      continue;
    if (s[i - 1] == 'x')
      continue;

    cout << i << endl;
  }

  /*
  cout << "in" << endl;
  for(auto x:in) cout << x << " ";
  cout << endl << "out" << endl;
  for(auto x:out) cout << x << " ";
  cout << endl;
  */
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> hidari(n + 2, 0);
  vector<int> migi(n + c + 3, 0);

  for (int i = 1; i <= n; ++i) {
    if (s[i - 1] == 'x') {
      hidari[i] = hidari[i - 1];
    } else {
      if (i - c - 1 <= 0) {
        hidari[i] = 1;
      } else {
        hidari[i] = hidari[i - c - 1] + 1;
      }
    }
  }

  vector<int> in(n + 2, 0);
  vector<int> out(n + 2, 0);

  for (int i = n + 1; i > 0; --i) {
    if (i - 1 >= n) {
      migi[i] = 0;
    } else if (s[i - 1] == 'x') {
      if (i + 1 <= n)
        migi[i] = migi[i + 1];
    } else {
      if (i + 1 + c > n)
        migi[i] = 1;
      else {
        migi[i] = migi[i + 1 + c] + 1;
      }
    }

    /*
    int temp = migi[i];
    if(i-c-1>=0){
        temp +=hidari[i-c-1];
    }
    if(temp>=k){
        cout << "i: "<<i<<endl;
        out[i]+=1;
        if(i-c>=0) in[i-c]+=1;
        else in[0]+=1;
    }*/
  }

  if (c == 0) {
    if (hidari[n] > k) {
      return 0;
    } else {
      rep(i, n) { cout << i + 1 << endl; }
    }
    return 0;
  }

  for (int r = 1; r <= (n + c + 1); ++r) {
    int temp = migi[r];
    if (r - c - 1 >= 0) {
      temp += hidari[r - c - 1];
    }
    if (temp >= k) {
      out[r] += 1;
      if (r - c >= 0) {
        in[r - c] += 1;
      } else
        in[0] += 1;
    }
  }

  /*
  for(auto h:hidari){
      cout << h << " ";
  }
  cout << endl;
  for(auto m:migi){
      cout << m << " ";
  }
  cout << endl;
  */
  int temp = 0;
  rep(i, n + 1) {
    temp += in[i];
    temp -= out[i];
    // cout <<"i: "<< i <<"t:" <<temp << endl;
    if (temp >= 1) {
      continue;
    }

    if (i == 0)
      continue;
    if (s[i - 1] == 'x')
      continue;

    cout << i << endl;
  }

  /*
  cout << "in" << endl;
  for(auto x:in) cout << x << " ";
  cout << endl << "out" << endl;
  for(auto x:out) cout << x << " ";
  cout << endl;
  */
}