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

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked() {
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if (s == e && e == 1048576) {
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if (s == e) {
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x) {
  int k;
  int m = 0;
  x = 0;
  for (;;) {
    k = my_getchar_unlocked();
    if (k == '-') {
      m = 1;
      break;
    }
    if ('0' <= k && k <= '9') {
      x = k - '0';
      break;
    }
  }
  for (;;) {
    k = my_getchar_unlocked();
    if (k < '0' || k > '9') {
      break;
    }
    x = x * 10 + k - '0';
  }
  if (m) {
    x = -x;
  }
}
inline void rd(char &c) {
  int i;
  for (;;) {
    i = my_getchar_unlocked();
    if (i != ' ' && i != '\\n' && i != '\\r' && i != '\\t' && i != EOF) {
      break;
    }
  }
  c = i;
}
inline int rd(char c[]) {
  int i;
  int sz = 0;
  for (;;) {
    i = my_getchar_unlocked();
    if (i != ' ' && i != '\\n' && i != '\\r' && i != '\\t' && i != EOF) {
      break;
    }
  }
  c[sz++] = i;
  for (;;) {
    i = my_getchar_unlocked();
    if (i == ' ' || i == '\\n' || i == '\\r' || i == '\\t' || i == EOF) {
      break;
    }
    c[sz++] = i;
  }
  c[sz] = '\\0';
  return sz;
}
struct MY_WRITER {
  char buf[1048576];
  int s;
  int e;
  MY_WRITER() {
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER() {
    if (s) {
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
};
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a) {
  if (MY_WRITER_VAR.s == MY_WRITER_VAR.e) {
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a) { my_putchar_unlocked(a); }
inline void wt_L(int x) {
  int s = 0;
  int m = 0;
  char f[10];
  if (x < 0) {
    m = 1;
    x = -x;
  }
  while (x) {
    f[s++] = x % 10;
    x /= 10;
  }
  if (!s) {
    f[s++] = 0;
  }
  if (m) {
    my_putchar_unlocked('-');
  }
  while (s--) {
    my_putchar_unlocked(f[s] + '0');
  }
}
template <class S, class T> inline S chmax(S &a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}
int N;
int K;
int C;
char S[200000 + 2];
int dp1[200000 + 1];
int dp2[200000 + 1];
int ress;
int res[200000];
int main() {
  int i;
  rd(N);
  rd(K);
  rd(C);
  rd(S);
  for (i = (N)-1; i >= (0); i--) {
    dp1[i] = dp1[i + 1];
    if (S[i] == 'x') {
      continue;
    }
    if (i + 1 + C <= N) {
      chmax(dp1[i], 1 + dp1[i + 1 + C]);
    } else {
      chmax(dp1[i], 1);
    }
  }
  if (dp1[0] > K) {
    return 0;
  }
  for (i = (0); i < (N); i++) {
    dp2[i + 1] = dp2[i];
    if (S[i] == 'x') {
      continue;
    }
    if (i - C >= 0) {
      chmax(dp2[i + 1], 1 + dp2[i - C]);
    } else {
      chmax(dp2[i + 1], 1);
    }
  }
  for (i = (0); i < (N); i++) {
    if (dp1[i] > dp1[i + 1] && dp2[i] < dp2[i + 1]) {
      wt_L(i + 1);
      wt_L('\\n');
    }
  }
  return 0;
}
// cLay varsion 20200404-1

// --- original code ---
// int N, K, C;
// char S[2d5+2];
// int dp1[2d5+1], dp2[2d5+1];
// int ress, res[2d5];
// {
//   rd(N,K,C,S);
//   rrep(i,N){
//     dp1[i] = dp1[i+1];
//     if(S[i]=='x') continue;
//     dp1[i] >?= if[i+1+C <= N, 1 + dp1[i+1+C], 1];
//   }
//   if(dp1[0] > K) return 0;
//
//   rep(i,N){
//     dp2[i+1] = dp2[i];
//     if(S[i]=='x') continue;
//     dp2[i+1] >?= if[i-C >= 0, 1 + dp2[i-C], 1];
//   }
//
//   rep(i,N) if(dp1[i]>dp1[i+1] && dp2[i]<dp2[i+1]) wt(i+1);
//
// }


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int NAX = 2e5 + 5;
int storeL[NAX], storeR[NAX];
int idxL[NAX], idxR[NAX];
class Solution {
private:
public:
  Solution() {}
  ~Solution() {}
  void solveCase() {
    int n, k, c;
    cin >> n >> k >> c;
    string a;
    cin >> a;
    a = '$' + a;
    int prev = -1e9, val = 0;
    for (size_t i = 1; i <= n; i++) {
      idxL[i] = prev;
      if (a[i] == 'x')
        storeL[i] = val;
      else {
        if (i - prev > c) {
          val++;
          prev = i;
          storeL[i] = val;
        }
      }
    }
    prev = 1e9, val = 0;
    for (size_t i = n; i >= 1; i--) {
      idxR[i] = prev;
      if (a[i] == 'x')
        storeR[i] = val;
      else {
        if (prev - i > c) {
          val++;
          prev = i;
          storeR[i] = val;
        }
      }
    }
    vector<int> ans;
    for (size_t i = 1; i <= n; i++) {
      int l = idxL[i];
      int r = idxR[i];
      if (l == -1e9 && r == 1e9)
        ans.pb(i);
      else if (l == -1e9) {
        if (storeR[r] < k)
          ans.pb(i);
      } else if (r == 1e9) {
        if (storeL[l] < k)
          ans.pb(i);
      } else {
        if (abs(r - l) > c) {
          if (storeL[l] + storeR[r] < k)
            ans.pb(i);
        } else {
          if (storeL[l] + storeR[r] - 1 < k)
            ans.pb(i);
        }
      }
    }
    for (auto &x : ans)
      cout << x << endl;
  }
};
int main() {
  cin.tie(0);
  int t = 1;
  cin >> t;
  Solution mySolver;
  for (int i = 1; i <= t; ++i) {
    mySolver.solveCase();
  }
  return 0;
}