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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\\n") : printf("No\\n")
#define YESNO(a) (a) ? printf("YES\\n") : printf("NO\\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int N, K, C;
  Scd3(N, K, C);

  static char s[2232133];
  Scs(s);

  int t = 0;
  int lim = 0;
  vi dp(N, -1);
  vi dlim(N + 1, INF);
  while (t < N) {
    if (s[t] == 'o')
      dlim[lim] = t, dp[t] = K - lim, lim++, t += C;
    t++;
  }
  if (lim > K) {
    return 0;
  }

  t = K - 1;
  RRep(i, N) {
    if (dp[i] != -1)
      t--;
    else if (s[i] == 'o' && i + C < dlim[t + 1])
      dlim[t] = max((int)i, dlim[t]);
  }

  t = 0;
  vi ans;
  Rep(i, N) {
    // cout << t << "!" << i << endl;
    if (dp[i] != -1 && dlim[t++] == i)
      ans.push_back(i);
  }

  for (int aa : ans) {
    printf("%d\\n", aa + 1);
  }

  // Rep(i,N){
  //     printf ("!%d\\n", dp[i] );
  // }
  // Rep(i,K){
  //     printf ("?%d\\n", dlim[i] );
  // }

  return 0;
}

/*
16 4 3
ooxx
oxoxxx
oxoxx
o
*/


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\\n") : printf("No\\n")
#define YESNO(a) (a) ? printf("YES\\n") : printf("NO\\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int N, K, C;
  Scd3(N, K, C);

  static char s[2232133];
  Scs(s);

  vi ok;
  Rep(i, N) if (s[i] == 'o') ok.push_back(i);

  int t = 0;
  int lim = 0;
  vi dp(N, -1);
  vi dlim(K + 1, INF);
  while (t < N) {
    if (s[t] == 'o')
      dlim[lim] = t, dp[t] = K - lim, lim++, t += C;
    t++;
  }
  if (lim > K) {
    return 0;
  }

  t = K - 1;
  RRep(i, N) {
    if (dp[i] != -1)
      t--;
    else if (s[i] == 'o' && i + C < dlim[t + 1])
      dlim[t] = i;
  }

  t++;
  vi ans;
  Rep(i, N) {
    // cout << t << "!" << i << endl;
    if (dp[i] != -1 && dlim[t++] == i)
      ans.push_back(i);
  }

  for (int aa : ans) {
    printf("%d\\n", aa + 1);
  }

  // Rep(i,N){
  //     printf ("!%d\\n", dp[i] );
  // }
  // Rep(i,K){
  //     printf ("?%d\\n", dlim[i] );
  // }

  return 0;
}

/*
16 4 3
ooxx
oxoxxx
oxoxx
o
*/