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

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
// #define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v)                                                         \\
  REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\\n" : " ")
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 2000020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int sumL[300020], sumR[300020];
pair<int, int> dp[300020];
pair<int, int> rev[300020];
void solve() {

  // test();
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  int cnt = 0;
  int idx = 0;
  dp[0] = {0, -100010};
  REP(i, N) {
    pii pre = dp[i];
    dp[i + 1] = pre;
    if (S[i] == 'o') {
      if (i < C) {
        if (dp[i + 1].first)
          continue;
        else {
          dp[i + 1] = {1, i};
        }
      } else {
        pre = dp[i - C];
        if (pre.first + 1 > dp[i + 1].first) {
          dp[i + 1] = {pre.first + 1, i};
        }
      }
    }
  }
  string T = S;
  VREVERSE(T);
  REP(i, N) {
    pii pre = rev[i];
    rev[i + 1] = pre;
    if (T[i] == 'o') {
      if (i < C) {
        if (rev[i + 1].first)
          continue;
        else {
          rev[i + 1] = {1, i};
        }
      } else {
        pre = rev[i - C];
        if (pre.first + 1 > rev[i + 1].first) {
          rev[i + 1] = {pre.first + 1, i};
        }
      }
    }
  }
  vector<int> A(N), cum(N + 1);
  REP(i, N) {
    if (i > 0)
      sumL[i] += sumL[i - 1];
    if (S[i] == 'o') {
      sumL[i]++;
      sumL[i + 1]--;
      sumL[i + C + 1]++;
    }
  }
  FORR(i, N, 0) {
    sumR[i] += sumR[i + 1];
    if (S[i] == 'o') {
      sumR[i]++;
      if (i)
        sumR[i - 1]--;
      if (i - C - 1 >= 0)
        sumR[i - C - 1]++;
    }
  }
  while (idx < N) {
    if (S[idx] == 'o') {
      cnt++;
      idx += 2 * C + 1;
    } else {
      idx++;
    }
  }
  if (cnt > K) {
    cout << endl;
    return;
  }
  REP(i, N) {
    if (S[i] == 'o')
      A[i] = 1;
  }
  REP(i, N) { cum[i + 1] = cum[i] + A[i]; }
  vector<int> ans;
  REP(i, N) {
    if (S[i] == 'o') {
      pii p = dp[i];
      // cout << i << " " << p.first <<" "<< p.second << endl;
      int las = p.second;
      int nxt = las + C + 1;
      if (nxt <= i)
        nxt = i + 1;
      // cout << nxt << " " << rev[N-nxt].first << endl;
      if (p.first + rev[max(0LL, N - nxt)].first < K)
        ans.push_back(i + 1);
    }
  }
  for (auto x : ans) {
    print(x);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // int q; cin >> q;
  // while (q--)
  solve();
}


Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
// #define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v)                                                         \\
  REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\\n" : " ")
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
  if (a > b)
    a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
  if (a < b)
    a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 2000020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int sumL[300020], sumR[300020];
pair<int, int> dp[300020];
pair<int, int> rev[300020];
void solve() {

  // test();
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  int cnt = 0;
  int idx = 0;
  dp[0] = {0, -100010};
  REP(i, N) {
    pii pre = dp[i];
    dp[i + 1] = pre;
    if (S[i] == 'o') {
      if (i < C) {
        if (dp[i + 1].first)
          continue;
        else {
          dp[i + 1] = {1, i};
        }
      } else {
        pre = dp[i - C];
        if (pre.first + 1 > dp[i + 1].first) {
          dp[i + 1] = {pre.first + 1, i};
        }
      }
    }
  }
  string T = S;
  VREVERSE(T);
  REP(i, N) {
    pii pre = rev[i];
    rev[i + 1] = pre;
    if (T[i] == 'o') {
      if (i < C) {
        if (rev[i + 1].first)
          continue;
        else {
          rev[i + 1] = {1, i};
        }
      } else {
        pre = rev[i - C];
        if (pre.first + 1 > rev[i + 1].first) {
          rev[i + 1] = {pre.first + 1, i};
        }
      }
    }
  }
  vector<int> A(N), cum(N + 1);
  REP(i, N) {
    if (i > 0)
      sumL[i] += sumL[i - 1];
    if (S[i] == 'o') {
      sumL[i]++;
      sumL[i + 1]--;
      sumL[i + C + 1]++;
    }
  }
  FORR(i, N, 0) {
    sumR[i] += sumR[i + 1];
    if (S[i] == 'o') {
      sumR[i]++;
      if (i)
        sumR[i - 1]--;
      if (i - C - 1 >= 0)
        sumR[i - C - 1]++;
    }
  }
  while (idx < N) {
    if (S[idx] == 'o') {
      cnt++;
      idx += 2 * C + 1;
    } else {
      idx++;
    }
  }
  if (cnt > K) {
    cout << endl;
    return;
  }
  REP(i, N) {
    if (S[i] == 'o')
      A[i] = 1;
  }
  REP(i, N) { cum[i + 1] = cum[i] + A[i]; }
  vector<int> ans;
  REP(i, N) {
    if (S[i] == 'o') {
      pii p = dp[i];
      // cout << i << " " << p.first <<" "<< p.second << endl;
      int las = p.second;
      int nxt = las + C + 1;
      if (nxt <= i)
        nxt = i + 1;
      // cout << nxt << " " << rev[N-nxt].first << endl;
      if (p.first + rev[N - nxt].first < K)
        ans.push_back(i + 1);
    }
  }
  for (auto x : ans) {
    print(x);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // int q; cin >> q;
  // while (q--)
  solve();
}