alexjercan/bugnet huggingface dataset:
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

int l[200010];
int r[200010];

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

  int num = 0;
  int now = 0;
  while (now < n) {
    if (s[now] == 'o') {
      l[++num] = now;
      now += c + 1;
    } else {
      now++;
    }
  }

  num = k;
  now = n - 1;
  while (now >= 0) {
    if (s[now] == 'o') {
      r[num--] = now;
      if (num <= 0)
        break;
      now -= c + 1;
    } else {
      now--;
    }
  }

  for (int i = 1; i <= k; ++i) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

int l[200010];
int r[200010];

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

  int num = 0;
  int now = 0;
  while (now < n) {
    if (s[now] == 'o') {
      l[++num] = now;
      now += c + 1;
    } else {
      now++;
    }
  }

  num = k;
  now = n - 1;
  while (now >= 0) {
    if (s[now] == 'o') {
      r[num--] = now;
      now -= c + 1;
    } else {
      now--;
    }
  }

  for (int i = 1; i <= k; ++i) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, c;
  string str;
  cin >> n >> k >> c;
  cin >> str;
  vector<int> l, r;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'x')
      continue;
    l.push_back(i + 1);
    if (l.size() == k)
      break;
    i += c;
  }
  for (int j = n - 1; j >= 0; j--) {
    if (str[j] == 'x')
      continue;
    r.push_back(j + 1);
    if (r.size() == k)
      break;
    j -= c;
  }
  sort(begin(r), end(r));
  vector<int> ans;
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i]) {
      ans.push_back(l[i]);
    }
  }
  for (auto &&i : ans) {
    cout << i << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int n, k, c;
string str;
set<int> s;
int dontcheck = -1;
vector<int> ans;
pair<int, int> p[200001];

bool dfs(int now, int have) {
  if (n < now)
    return false;
  if (have == 0)
    return true;
  if (p[now].first != dontcheck) {
    return dfs(p[now].first, have - 1);
  } else {
    return dfs(p[now].second, have - 1);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> c;
  cin >> str;
  static const int INF = 1e9 + 7;
  s.insert(INF);
  s.insert(INF + 1);
  for (int i = 0; i < n; i++) {
    if (str[i] == 'o') {
      s.insert(i + 1);
    }
  }

  for (auto &&i : s) {
    if (n < i)
      continue;
    p[i] =
        make_pair(*s.upper_bound(i + c), *s.upper_bound(*s.upper_bound(i + c)));
  }
  p[0] = make_pair(*s.upper_bound(0), *s.upper_bound(*s.upper_bound(0)));
  ;
  for (int i = 1; i <= n; i++) {
    if (str[i - 1] == 'x')
      continue;
    dontcheck = i;
    if (!dfs(0, k)) {
      ans.push_back(i);
    }
  }
  for (auto &&i : ans) {
    cout << i << "\\n";
  }
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define vcout(v)                                                               \\
  rep(i, v.size()) cout << v[i] << " ";                                        \\
  cout << endl
#define mcout(m)                                                               \\
  rep(j, m.size()) { vcout(m[j]); }
const ll MOD = 1e9 + 7;

int mainsolve() {

  ll n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;

  vector<ll> tmp1, tmp2, res;

  rep(i, n) {
    if (!tmp1.empty() && i - tmp1.back() <= c)
      continue;
    if (s[i] == 'o')
      tmp1.push_back(i);
    if (tmp1.size() == k)
      break;
  }

  for (ll i = n - 1; i >= 0; i--) {
    if (!tmp2.empty() && tmp2.back() - i <= c)
      continue;
    if (s[i] == 'o')
      tmp2.push_back(i);
    if (tmp2.size() == k)
      break;
  }

  rep(i, k) {
    if (tmp1[i] == tmp2[k - 1 - i]) {
      cout << tmp1[i] + 1 << endl;
    }
  }

  return 0;
}

int main() { return mainsolve(); }

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define vcout(v)                                                               \\
  rep(i, v.size()) cout << v[i] << " ";                                        \\
  cout << endl
#define mcout(m)                                                               \\
  rep(j, m.size()) { vcout(m[j]); }
const ll MOD = 1e9 + 7;

int mainsolve() {

  ll n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;

  vector<ll> tmp1, tmp2, res;

  rep(i, n) {
    if (!tmp1.empty() && i - tmp1.back() <= c)
      continue;
    if (s[i] == 'o')
      tmp1.push_back(i);
    if (tmp1.size() == k)
      break;
  }

  for (ll i = n - 1; i >= 0; i--) {
    if (!tmp2.empty() && tmp2.back() - i <= c)
      continue;
    if (s[i] == 'o')
      tmp2.push_back(i);
    if (tmp2.size() == k)
      break;
  }

  if (tmp1.empty() || tmp2.empty()) {
    return 0;
  }

  set<ll> st;
  for (auto i : tmp2)
    st.insert(i);

  for (auto i : tmp1) {
    if (st.find(i) != st.end()) {
      res.push_back(i);
    }
  }

  /*
      assert(res.size() <= k);
      if(res.size() >= 2) rep(i,res.size()-1) assert(res[i] < res[i+1]);
      rep(i,res.size()) assert(s[res[i]] == 'o');
  */

  assert(!res.empty());
  for (auto i : res) {
    cout << i + 1 << endl;
  }

  return 0;
}

int main() { return mainsolve(); }
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long long n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  map<long long, long long> m1;
  map<long long, long long> m2;
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'o') {
      count++;
      m1[i + 1] = count;
      if (count == k)
        break;
      i += c;
    }
  }
  count = 0;
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      count++;
      m2[i + 1] = k + 1 - count;
      i -= c;
      if (count == k)
        break;
    }
  }
  for (auto i : m1) {
    long long t = i.first;
    if (i.second == m2[t])
      cout << i.first << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> a(k);
  vector<int> b(k);
  int j = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[j++] = i;

      i += c;
    }
  }
  j = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b[j--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++) {
    for (j = 0; j < k; j++) {
      if (a[i] == b[j])
        cout << a[i] + 1 << endl;
    }
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

// 3/4/20 20:45
// nifty 8083.80

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<long, long>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define Mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define endl '\\n'
#define mod 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rem(i, a, b) for (int i = a; i > b; i--)
#define mp(a, b) make_pair(a, b)
#define INF numeric_limits<ll>::max();
#define NINF numeric_limits<ll>::min();
#define vvi(a, b, name) vector<vector<int>> name(a, vector<int>(b, -1))

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int l[k], r[k];
  int b = 0, e = k - 1;
  int ind = -1;
  for (int i = 0; i < n && b < k; i++) {
    if (s[i] == 'o' && i > ind) {
      l[b] = i;
      b++;
      ind = i + c;
    }
  }

  ind = n;
  for (int i = n - 1; i >= 0 && e >= 0; i--) {
    if (s[i] == 'o' && i < ind) {
      r[e] = i;
      e--;
      ind = i - c;
    }
  }
  // int cnt=0;
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
    // cout<<l[i]<<" "<<r[i]<<endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

// 3/4/20 20:45
// nifty 8083.80

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<long, long>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define Mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define endl '\\n'
#define mod 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rem(i, a, b) for (int i = a; i > b; i--)
#define mp(a, b) make_pair(a, b)
#define INF numeric_limits<ll>::max();
#define NINF numeric_limits<ll>::min();
#define vvi(a, b, name) vector<vector<int>> name(a, vector<int>(b, -1))

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int l[k], r[k];
  int b = 0, e = k - 1;
  int ind = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && i > ind) {
      l[b] = i;
      b++;
      ind = i + c;
    }
  }

  ind = n;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o' && i < ind) {
      r[e] = i;
      e--;
      ind = i - c;
    }
  }
  // int cnt=0;
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
    // cout<<l[i]<<" "<<r[i]<<endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> G, G2;
  int p = -INF;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'o' && i > p + C) {
      G.push_back(i);
      p = i;
    }
    if (G.size() == K) {
      break;
    }
  }
  p = INF;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'o' && i < p - C) {
      G2.push_back(i);
      p = i;
    }
    if (G2.size() == K) {
      break;
    }
  }
  reverse(G2.begin(), G2.end());
  for (int i = 0; i < K; i++) {
    if (G[i] == G2[i]) {
      cout << G[i] + 1 << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> G, G2;
  int p = -INF;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'o' && i > p + C) {
      G.push_back(i);
      p = i;
    }
    if (G.size() == K) {
      break;
    }
  }
  p = INF;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'o' && i < p - C) {
      G2.push_back(i);
      p = i;
    }
    if (G2.size() == K) {
      break;
    }
  }
  reverse(G2.begin(), G2.end());
  for (int i = 0; i < K; i++) {
    if (G[i] == G2[i]) {
      cout << G[i] + 1 << endl;
    }
  }
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

inline void chk_max(int &a, int b) {
  if (a < b)
    a = b;
}

char s[MAXN];
int pre[MAXN], suf[MAXN];
ll dif[MAXN];
inline void update(int l, int r) {
  ++dif[l];
  --dif[r + 1];
}

int main(void) {
  int n, d, c;
  scanf("%d%d%d%s", &n, &d, &c, s + 1);

  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1];
    if (s[i] == 'x')
      continue;
    chk_max(pre[i], 1);
    if (i - c - 1 >= 1)
      chk_max(pre[i], pre[i - c - 1] + 1);
  }
  for (int i = n; i >= 1; --i) {
    suf[i] = suf[i + 1];
    if (s[i] == 'x')
      continue;
    chk_max(suf[i], 1);
    if (i + c + 1 <= n)
      chk_max(suf[i], suf[i + c + 1] + 1);
  }

  for (int i = 1; i <= n; ++i) {
    if (pre[i - 1] >= d || suf[i + 1] >= d)
      update(i, i);
  }

  if (c) {
    for (int i = 1; i + c - 1 <= n; ++i) {
      int j = i + c - 1;
      if (pre[i - 1] + suf[j + 1] >= d)
        update(i, j);
    }
  } else {
    for (int i = 1; i <= n; ++i)
      if (pre[i - 1] + suf[i + 1] >= d)
        update(i, i);
  }

  for (int i = 1; i <= n; ++i)
    dif[i] += dif[i - 1];

  for (int i = 1; i <= n; ++i)
    if (s[i] == 'o' && !dif[i])
      printf("%d\\n", i);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

inline void chk_max(int &a, int b) {
  if (a < b)
    a = b;
}

char s[MAXN];
int pre[MAXN], suf[MAXN];
ll dif[MAXN];
inline void update(int l, int r) {
  ++dif[l];
  --dif[r + 1];
}

vector<int> ans1, ans2;

int main(void) {
  int n, d, c;
  scanf("%d%d%d%s", &n, &d, &c, s + 1);

  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1];
    if (s[i] == 'x')
      continue;
    chk_max(pre[i], 1);
    if (i - c - 1 >= 1)
      chk_max(pre[i], pre[i - c - 1] + 1);
  }
  for (int i = n; i >= 1; --i) {
    suf[i] = suf[i + 1];
    if (s[i] == 'x')
      continue;
    chk_max(suf[i], 1);
    if (i + c + 1 <= n)
      chk_max(suf[i], suf[i + c + 1] + 1);
  }

  // for(int i=1; i<=n; ++i) printf("%d %d\\n",pre[i],suf[i]);

  for (int i = 1; i <= n; ++i)
    if (pre[i - 1] + suf[i + 1] < d)
      ans1.push_back(i);
  //			printf("%d\\n",i);

  for (int i = 1; i <= n; ++i) {
    if (pre[i - 1] >= d || suf[i + 1] >= d)
      update(i, i);
  }
  for (int i = 1; i + c - 1 <= n; ++i) {
    int j = i + c - 1;
    if (pre[i - 1] + suf[j + 1] >= d)
      update(i, j);
  }
  for (int i = 1; i <= n; ++i)
    dif[i] += dif[i - 1];

  for (int i = 1; i <= n; ++i)
    if (s[i] == 'o' && !dif[i])
      ans2.push_back(i);
  //			printf("%d\\n",i);

  if (ans1.size() == ans2.size()) {
    for (int i = 0; i < (int)ans2.size(); ++i)
      printf("%d\\n", ans2[i]);
    return 0;
  }

  if (c)
    while (1)
      ;
  else
    return 114514;
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> can;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o')
      can.emplace_back(i);
  }
  int m = can.size();
  vector<int> days(m);
  for (int i = m - 1; i >= 0; i--) {
    auto it = upper_bound(can.begin(), can.end(), can[i] + c);
    if (it == can.end())
      days[i] = 1;
    else {
      int j = distance(can.begin(), it);
      days[i] = days[j] + 1;
    }
  }
  if (days.front() > k) {
    cout << endl;
    return 0;
  }
  int lim = -1;
  ;
  for (int i = 0; i < m; i++) {
    if (i == 0) {
      if (days[i] != days[i + 1])
        ans.emplace_back(can[i] + 1);
      lim = can[i] + c;
    } else if (can[i] <= lim)
      continue;
    else if (i == m - 1)
      ans.emplace_back(can[i] + 1);
    else {
      lim = can[i] + c;
      if (days[i] != days[i + 1])
        ans.emplace_back(can[i] + 1);
    }
  }
  if (!ans.size())
    cout << endl;
  else
    for (auto &el : ans)
      cout << el << endl;
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> can;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o')
      can.emplace_back(i);
  }
  vector<int> days(can.size());
  for (int i = n - 1; i >= 0; i--) {
    auto it = upper_bound(can.begin(), can.end(), can[i] + c);
    if (it == can.end())
      days[i] = 1;
    else {
      int j = distance(can.begin(), it);
      days[i] = days[j] + 1;
    }
  }
  if (days.front() > k) {
    cout << endl;
    return 0;
  }
  int lim = -1;
  ;
  for (int i = 0; i < days.size(); i++) {
    if (i == 0) {
      if (days[i] != days[i + 1]) {
        ans.emplace_back(can[i] + 1);
        lim = can[i] + c;
      }
    } else if (i == days.size() - 1) {
      if (can[i - 1] <= lim || days[i] != days[i - 1]) {
        ans.emplace_back(can[i] + 1);
      }
    } else if (can[i] <= lim)
      continue;
    else if (can[i - 1] <= lim) {
      if (days[i] != days[i + 1]) {
        ans.emplace_back(can[i] + 1);
        lim = can[i] + c;
      }
    } else {
      if (days[i] != days[i - 1] && days[i] != days[i + 1]) {
        ans.emplace_back(can[i] + 1);
        lim = can[i] + c;
      }
    }
  }
  if (!ans.size())
    cout << endl;
  else
    for (auto &el : ans)
      cout << el << endl;
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  vector<int> A(N);
  int prev = -C - 1;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (i > prev + C and S[i] == 'o') {
      ++cnt;
      prev = i;
    }
    A[i] = cnt;
  }

  vector<int> B(N);
  int next = N + C;
  cnt = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (i < next - C and S[i] == 'o') {
      ++cnt;
      next = i;
    }
    B[i] = cnt;
  }

  if (B[1] < K) {
    cout << 0 + 1 << endl;
  }
  for (int i = 1; i < N - 1; ++i) {
    if (A[i - 1] + B[i + 1] < K) {
      cout << i + 1 << endl;
    }
  }
  if (A[N - 2] < K) {
    cout << N - 1 + 1 << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;

  vector<vector<ll>> A(N, vector<ll>(K));
  {
    int j = 0;
    for (int i = 0; i < N; ++i) {
      if (S[i] == 'o') {
        A[i][j] = 1;
        for (int ni = i + C + 1; ni < N; ++ni) {
          if (S[ni] == 'o' and j + 1 < K)
            A[ni][j + 1] += A[i][j];
        }
      }
    }
  }
  for (int j = 1; j < K; ++j) {
    for (int i = 0; i < N; ++i) {
      if (A[i][j] != 0) {
        for (int ni = i + C + 1; ni < N; ++ni) {
          if (S[ni] == 'o' and j + 1 < K)
            A[ni][j + 1] += A[i][j];
        }
      }
    }
  }

  int total = 0;
  for (int i = 0; i < N; ++i) {
    total += A[i][K - 1];
  }

  vector<vector<ll>> B(N, vector<ll>(K));
  {
    int j = K - 1;
    for (int i = 0; i < N; ++i) {
      if (S[i] == 'o') {
        B[i][j] = 1;
        for (int pi = i - C - 1; pi >= 0; --pi) {
          if (S[pi] == 'o' and j - 1 >= 0)
            B[pi][j - 1] += B[i][j];
        }
      }
    }
  }
  for (int j = K - 2; j >= 0; --j) {
    for (int i = 0; i < N; ++i) {
      if (B[i][j] != 0) {
        for (int pi = i - C - 1; pi >= 0; --pi) {
          if (S[pi] == 'o' and j - 1 >= 0)
            B[pi][j - 1] += B[i][j];
        }
      }
    }
  }

  for (int i = 0; i < N; ++i) {
    int sum = 0;
    for (int j = 0; j < K; ++j) {
      sum += A[i][j] * B[i][j];
    }
    if (sum == total) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long long int lli;

const int MAXN = 200010;

int n, k, c;

int dpPrefix[MAXN];
int dpSuffix[MAXN];
int mxDpPrefix[MAXN];
int mxDpSuffix[MAXN];

string s;

multiset<int> q;

int getMax() {
  auto it = q.end();
  it--;

  return *it;
}

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

  for (int i = 1; i <= n; i++) {
    int val = 0;
    if (i - c >= 1)
      val = mxDpPrefix[i - c - 1];

    dpPrefix[i] = val + 1;
    if (s[i - 1] == 'x')
      dpPrefix[i]--;

    mxDpPrefix[i] = max(mxDpPrefix[i - 1], dpPrefix[i]);
  }

  for (int i = n; i > 0; i--) {
    int val = 0;
    if (i + c <= n)
      val = mxDpSuffix[i + c + 1];

    dpSuffix[i] = val + 1;
    if (s[i - 1] == 'x')
      dpSuffix[i]--;

    mxDpSuffix[i] = max(mxDpSuffix[i + 1], dpSuffix[i]);
  }

  vector<int> ans;

  c = max(c, 1);
  // c = min( c , n - 1 );

  for (int i = 2; i <= c + 1; i++)
    q.insert(mxDpSuffix[i]);

  for (int i = 1; i <= s.size(); i++) {
    if (getMax() < k && s[i - 1] == 'o')
      ans.push_back(i);

    int r = 0;
    if (i - c >= 1)
      r += mxDpPrefix[i - c];
    if (i + 1 <= n)
      r += mxDpSuffix[i + 1];

    q.erase(q.find(r));

    r = mxDpPrefix[i];
    if (i + c + 1 <= n)
      r += mxDpSuffix[i + c + 1];

    q.insert(r);
  }

  for (int i = 0; i < ans.size(); i++)
    printf("%d\\n", ans[i]);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long long int lli;

const int MAXN = 200010;

int n, k, c;

int dpPrefix[MAXN];
int dpSuffix[MAXN];
int mxDpPrefix[MAXN];
int mxDpSuffix[MAXN];

string s;

multiset<int> q;

int getMax() {
  auto it = q.end();
  it--;

  return *it;
}

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

  for (int i = 1; i <= n; i++) {
    int val = 0;
    if (i - c >= 1)
      val = mxDpPrefix[i - c - 1];

    dpPrefix[i] = val + 1;
    if (s[i - 1] == 'x')
      dpPrefix[i]--;

    mxDpPrefix[i] = max(mxDpPrefix[i - 1], dpPrefix[i]);
  }

  for (int i = n; i > 0; i--) {
    int val = 0;
    if (i + c <= n)
      val = mxDpSuffix[i + c + 1];

    dpSuffix[i] = val + 1;
    if (s[i - 1] == 'x')
      dpSuffix[i]--;

    mxDpSuffix[i] = max(mxDpSuffix[i + 1], dpSuffix[i]);
  }

  vector<int> ans;

  c = max(c, 1);

  for (int i = 2; i <= s.size() && i <= c + 1; i++)
    q.insert(mxDpSuffix[i]);

  for (int i = 1; i <= s.size(); i++) {
    if (getMax() < k && s[i - 1] == 'o')
      ans.push_back(i);

    int r = 0;
    if (i - c > 0)
      r += mxDpPrefix[i - c];
    if (i + 1 <= n)
      r += mxDpSuffix[i + 1];

    q.erase(q.find(r));

    r = mxDpPrefix[i];
    if (i + c + 1 <= n)
      r += mxDpSuffix[i + c + 1];

    q.insert(r);
  }

  for (int i = 0; i < ans.size(); i++)
    printf("%d\\n", ans[i]);
}