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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
  for (ll i = 0; i < v.size(); ++i)
    x << v[i] << " ";
  return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
  for (auto it : v)
    x << it << " ";
  return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
  x << v.ff << " " << v.ss;
  return x;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v)
    os << it.first << "=>" << it.second << endl;
  return os;
}
struct pair_hash {
  inline std::size_t operator()(const std::pair<ll, ll> &v) const {
    return v.first * 31 + v.second;
  }
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m)                                                                \\
  for (auto it = m.begin(); it != m.end(); ++it) {                             \\
    cout << *it << endl;                                                       \\
  }
#define tra(it, m) for (auto it = m.begin(); it != m.end(); ++it)
#define DBG(x) cout << "# # #     " << x << '\\n';
#define fri(i, s, n) for (int i = s; i < n; i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll, ll>
#define rz(n) resize(n)
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define arrin(a, n)                                                            \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cin >> a[i];                                                               \\
  }
#define arrout(a, n)                                                           \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cout << a[i] << " ";                                                       \\
  }
#define ex(s) cout << s << endl, exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock                                                              \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
pair<int, int> dp[2][2 * N];
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  dp[0][0].fr = (s[0] == 'o');
  if (s[0] == 'o') {
    dp[0][0].sc = 0;
  } else {
    dp[0][0].sc = -1;
  }
  fri(i, 1, n) {
    if (s[i] == 'x') {
      dp[0][i] = dp[0][i - 1];
      continue;
    }
    if (i - c - 1 < 0) {
      if (dp[0][i - 1].fr == 0) {
        dp[0][i] = {1, i};
      } else {
        dp[0][i] = dp[0][i - 1];
      }
      continue;
    }
    dp[0][i] = dp[0][i - 1];
    if (dp[0][i - c - 1].fr + 1 > dp[0][i - 1].fr) {
      dp[0][i] = {dp[0][i - c - 1].fr + 1, i};
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  dp[1][n - 1].fr = (s[n - 1] == 'o');
  if (s[n - 1] == 'o') {
    dp[1][n - 1].sc = n - 1;
  } else {
    dp[1][n - 1].sc = n + 4;
  }
  for (int i = n - 2; i >= 0; i--) {
    dp[1][i] = dp[1][i + 1];
    if (s[i] == 'x') {
      dp[1][i] = dp[1][i + 1];
      continue;
    }
    if (i + c + 1 >= n) {
      if (dp[1][i + 1].fr == 0) {
        dp[1][i] = {1, i};
      }
      continue;
    }
    if (dp[1][i + c + 1].fr + 1 > dp[1][i + 1].fr) {
      dp[1][i] = {dp[1][i + c + 1].fr + 1, i};
    }
  }
  vct ans;
  if (dp[1][1].fr < k) {
    ans.pb(1);
  }
  fri(i, 1, n - 1) {
    if (s[i] == 'o') {
      int x1, x2;
      x1 = x2 = 0;
      int i1 = dp[1][i + 1].sc;
      if (i1 == n + 4) {
        x1 = dp[0][i - 1].fr;
      } else {
        x1 = -1; // ;dp[1][i+1].fr + dp[0][min(i-1,dp[1][i+1].sc-c-1)].fr;
      }
      int i2 = dp[0][i - 1].sc;
      if (i2 == -1) {
        x2 = dp[1][i + 1].fr;
      } else {
        x2 = dp[0][i - 1].fr + dp[1][max(i + 1, dp[0][i - 1].sc + c + 1)].fr;
      }
      if (max(x1, x2) < k) {
        ans.pb(i + 1);
      }
    }
  }
  if (dp[0][n - 2].fr < k) {
    ans.pb(n);
  }
  for (int i : ans) {
    cout << i << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
  for (ll i = 0; i < v.size(); ++i)
    x << v[i] << " ";
  return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
  for (auto it : v)
    x << it << " ";
  return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
  x << v.ff << " " << v.ss;
  return x;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
  for (auto it : v)
    os << it.first << "=>" << it.second << endl;
  return os;
}
struct pair_hash {
  inline std::size_t operator()(const std::pair<ll, ll> &v) const {
    return v.first * 31 + v.second;
  }
};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m)                                                                \\
  for (auto it = m.begin(); it != m.end(); ++it) {                             \\
    cout << *it << endl;                                                       \\
  }
#define tra(it, m) for (auto it = m.begin(); it != m.end(); ++it)
#define DBG(x) cout << "# # #     " << x << '\\n';
#define fri(i, s, n) for (int i = s; i < n; i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll, ll>
#define rz(n) resize(n)
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define arrin(a, n)                                                            \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cin >> a[i];                                                               \\
  }
#define arrout(a, n)                                                           \\
  for (ll i = 0; i < n; i++) {                                                 \\
    cout << a[i] << " ";                                                       \\
  }
#define ex(s) cout << s << endl, exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock                                                              \\
  cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
pair<int, int> dp[2][2 * N];
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  dp[0][0].fr = (s[0] == 'o');
  if (s[0] == 'o') {
    dp[0][0].sc = 0;
  } else {
    dp[0][0].sc = -1;
  }
  fri(i, 1, n) {
    if (s[i] == 'x') {
      dp[0][i] = dp[0][i - 1];
      continue;
    }
    if (i - c - 1 < 0) {
      if (dp[0][i - 1].fr == 0) {
        dp[0][i] = {1, i};
      } else {
        dp[0][i] = dp[0][i - 1];
      }
      continue;
    }
    dp[0][i] = dp[0][i - 1];
    if (dp[0][i - c - 1].fr + 1 > dp[0][i - 1].fr) {
      dp[0][i] = {dp[0][i - c - 1].fr + 1, i};
    }
  }
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  dp[1][n - 1].fr = (s[n - 1] == 'o');
  if (s[n - 1] == 'o') {
    dp[1][n - 1].sc = n - 1;
  } else {
    dp[1][n - 1].sc = n + 4;
  }
  for (int i = n - 2; i >= 0; i--) {
    dp[1][i] = dp[1][i + 1];
    if (s[i] == 'x') {
      dp[1][i] = dp[1][i + 1];
      continue;
    }
    if (i + c + 1 >= n) {
      if (dp[1][i + 1].fr == 0) {
        dp[1][i] = {1, i};
      }
      continue;
    }
    if (dp[1][i + c + 1].fr + 1 > dp[1][i + 1].fr) {
      dp[1][i] = {dp[1][i + c + 1].fr + 1, i};
    }
  }
  vct ans;
  if (dp[1][1].fr < k) {
    ans.pb(1);
  }
  fri(i, 1, n - 1) {
    if (s[i] == 'o') {
      int x1, x2;
      x1 = x2 = 0;
      int i1 = dp[1][i + 1].sc;
      if (i1 == -1) {
        x1 = dp[0][i - 1].fr;
      } else {
        x1 = dp[1][i + 1].fr + dp[0][min(i - 1, dp[1][i + 1].sc - c - 1)].fr;
      }
      int i2 = dp[0][i - 1].sc;
      if (i2 == -1) {
        x2 = dp[1][i + 1].fr;
      } else {
        x2 = dp[0][i - 1].fr + dp[1][max(i + 1, dp[0][i - 1].sc + c + 1)].fr;
      }
      if (max(x1, x2) < k) {
        ans.pb(i + 1);
      }
    }
  }
  if (dp[0][n - 2].fr < k) {
    ans.pb(n);
  }
  for (int i : ans) {
    cout << i << endl;
  }
}