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

#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a) - a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v, i)                                                             \\
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\\n" : " ");
#define vout(v) VOUT(v, z);
#define vdbg(v, i)                                                             \\
  cout << #v << ": ";                                                          \\
  for (int i = 0; i < (int)v.size(); i++) {                                    \\
    cout << v[i] << " ";                                                       \\
  }                                                                            \\
  cout << "\\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m, r, c)                                                          \\
  rep(i, r) {                                                                  \\
    rep(j, c) { cout << m[i][j] << " "; }                                      \\
    cout << endl;                                                              \\
  }
#define mout(m) MOUT(m, m.size(), m[0].size())
#define debg(a) cout << #a << ": " << a << endl;
#define show(a)                                                                \\
  for (cont & y : a) {                                                         \\
    for (cont & x : y) {                                                       \\
      cout << x << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
#define digit(a) to_string(a).length();
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
bool is_palindrome(string s) { return s == string(s.rbegin(), s.rend()); }
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> dp;
ll N, K, C;
string S;
ll casecnt;

void backtracking(ll cnt, ll day, vector<ll> dpk) {
  if (cnt == K) {
    for (long long i = 0; i < K; i++) {
      dp[dpk[i]]++;
    }
    casecnt++;
    return;
  }
  for (long long i = day; i < N; i++) {
    if (S[i] == 'o') {
      dpk[cnt] = i;
      // cnt++;
      // backtracking(cnt, i+C+1, dpk);
      // cnt--;
      // backtracking(cnt, i+1, dpk);
      backtracking(++cnt, i + C + 1, dpk);
      backtracking(--cnt, i + 1, dpk);
    }
  }
}

void solve_old() {
  vector<ll> dpk;
  dp.resize(N, 0);
  dpk.resize(K, 0);
  backtracking(0, 0, dpk);
  vout(dp);
  // cout << casecnt << endl;
  bool f = false;
  for (long long i = 0; i < N; i++) {
    if (dp[i] == casecnt) {
      cout << i + 1 << endl;
      f = true;
    }
  }
  if (f == false)
    cout << endl;
}

void solve() {
  // vector<ll> workday(N);
  vector<ll> l(2e5 + 10);
  vector<ll> r(2e5 + 10);
  ll cnt = 0;
  for (long long i = 0; i < N; i++) {
    if (S[i] == 'o') {
      // workday[i]++;
      l[cnt] = i;
      i += C;
      cnt++;
    }
    // if(cnt==K) break;
  }
  cnt = 0;
  for (long long i = N - 1; i >= 0; i--) {
    if (S[i] == 'o') {
      // workday[i]++;
      r[cnt] = i;
      i -= C;
      cnt++;
    }
    // if(cnt==K) break;
  }
  for (long long i = 0; i < K; i++) {
    if (l[i] == r[K - i - 1]) {
      cout << l[i] + 1 << endl;
    }
  }
  // for (long long i = 0; i < N; i++) {
  //     if(workday[i]==2){
  //         cout << i+1 << endl;
  //     }
  // }
}

int main() {
  // long long N;
  scanf("%lld", &N);
  // long long K;
  scanf("%lld", &K);
  // long long C;
  scanf("%lld", &C);
  // std::string S;
  std::cin >> S;
  // solve(N, K, C, S);
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, x, n) for (int i = x; i < (int)n; i++)
#define rep(i, n) REP(i, 0, n)
#define sp(p) cout << setprecision(16) << fixed << p << endl;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a) - a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v, i)                                                             \\
  rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\\n" : " ");
#define vout(v) VOUT(v, z);
#define vdbg(v, i)                                                             \\
  cout << #v << ": ";                                                          \\
  for (int i = 0; i < (int)v.size(); i++) {                                    \\
    cout << v[i] << " ";                                                       \\
  }                                                                            \\
  cout << "\\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m, r, c)                                                          \\
  rep(i, r) {                                                                  \\
    rep(j, c) { cout << m[i][j] << " "; }                                      \\
    cout << endl;                                                              \\
  }
#define mout(m) MOUT(m, m.size(), m[0].size())
#define debg(a) cout << #a << ": " << a << endl;
#define show(a)                                                                \\
  for (cont & y : a) {                                                         \\
    for (cont & x : y) {                                                       \\
      cout << x << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
#define digit(a) to_string(a).length();
template <class T> inline int out(const T &t) {
  print(t);
  putchar('\\n');
  return 0;
}
template <class T> inline T gcd(T a, T b) {
  if (b == 0)
    return a;
  return (gcd(b, a % b));
}
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
bool is_palindrome(string s) { return s == string(s.rbegin(), s.rend()); }
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> dp;
ll N, K, C;
string S;
ll casecnt;

void backtracking(ll cnt, ll day, vector<ll> dpk) {
  if (cnt == K) {
    for (long long i = 0; i < K; i++) {
      dp[dpk[i]]++;
    }
    casecnt++;
    return;
  }
  for (long long i = day; i < N; i++) {
    if (S[i] == 'o') {
      dpk[cnt] = i;
      cnt++;
      backtracking(cnt, i + C + 1, dpk);
      cnt--;
      backtracking(cnt, i + 1, dpk);
    }
  }
}

void solve() {
  vector<ll> dpk;
  dp.resize(N, 0);
  dpk.resize(K, 0);
  backtracking(0, 0, dpk);
  // vout(dp);
  // cout << casecnt << endl;
  bool f = false;
  for (long long i = 0; i < N; i++) {
    if (dp[i] == casecnt) {
      cout << i + 1 << endl;
      f = true;
    }
  }
  if (f == false)
    cout << endl;
}

int main() {
  // long long N;
  scanf("%lld", &N);
  // long long K;
  scanf("%lld", &K);
  // long long C;
  scanf("%lld", &C);
  // std::string S;
  std::cin >> S;
  // solve(N, K, C, S);
  solve();
  return 0;
}