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

//=======================//
// coder: Andy - Tohrumi //
//=======================//

#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \\
  ios_base::sync_with_stdio();                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, a, b) for (__typeof(b) i = a; i < b; ++i)
#define Rep(i, a, b) for (__typeof(a) i = a; i > b; --i)
#define mp make_pair
#define pb emplace_back

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

// code start here //

const int N = 200005;
int dp[N], pos[N];

signed main() {
  fastio;
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  rep(i, 1, n + 1) {
    if (s[i - 1] == 'x') {
      dp[i] = dp[i - 1];
      continue;
    }
    dp[i] = dp[i - c - 1] + 1;
  }
  int cur, temp = k;
  if (dp[n] > k)
    return 0;
  Rep(i, n, 0) {
    if (dp[i] == temp && s[i - 1] == 'o') {
      if (temp == k) {
        pos[dp[i]] = i;
        cur = i;
        temp--;
        continue;
      }
      if (i + c + 1 <= cur) {
        pos[dp[i]] = i;
        cur = i;
        temp--;
      }
    }
  }
  vi num[k + 1];
  rep(i, 1, n + 1) {
    if (s[i - 1] == 'o' && i <= pos[dp[i]]) {
      num[dp[i]].pb(i);
    }
  }
  rep(i, 1, k + 1) {
    if (num[i].size() == 1)
      cout << num[i][0] << endl;
  }
}

Error: 0

Fixed submission:

//=======================//
// coder: Andy - Tohrumi //
//=======================//

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio();                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define maxn 200001
#define pb push_back
#define fi first
#define se second

const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<int> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;

// code start here //

int dp[maxn], pos[maxn];
bool check[maxn];

signed main() {
  //	freopen("max_03.inp", "r", stdin);
  fastio;
  int n, k, c;
  cin >> n >> k >> c;
  int temp;
  string str;
  cin >> str;
  vector<int> ccc[k + 1];
  for (int i = 1; i <= n; i++) {
    if (str[i - 1] == 'o') {
      pos[i] = i;
      if (i - 1 - c < 0)
        dp[i] = 1;
      else
        dp[i] = dp[i - 1 - c] + 1;
    } else {
      pos[i] = pos[i - 1];
      dp[i] = dp[i - 1];
    }
  }
  if (dp[n] != k) {
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (str[i - 1] == 'o') {
      ccc[dp[i]].pb(i);
    }
  }
  vector<int> ans;
  for (int i = dp[n]; i >= 1; i--) {
    int cnt = 0;
    if (i == dp[n]) {
      if (ccc[i].size() == 1)
        ans.pb(ccc[i][0]);
      for (int j = 0; j < (int)ccc[i].size(); j++) {
        if (!check[ccc[i][j]]) {
          check[pos[ccc[i][j] - 1 - c]] = true;
        }
      }
    } else {
      for (int j = 0; j < (int)ccc[i].size(); j++) {
        if (check[ccc[i][j]]) {
          cnt++;
          temp = j;
        }
      }
      if (cnt == 1) {
        if (check[ccc[i][0]]) {
          ans.pb(ccc[i][0]);
          check[pos[ccc[i][0] - 1 - c]] = true;
        }

      } else {
        for (int j = 0; j <= temp; j++) {
          check[pos[ccc[i][j] - 1 - c]] = true;
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < (int)ans.size(); i++)
    cout << ans[i] << endl;
}