alexjercan/bugnet huggingface dataset:
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> l, r;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && l.size() < k) {
      l.push_back(i);
      i += c;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o' && r.size() < k) {
      r.push_back(i);
      i -= c;
    }
  }
  reverse(r.begin(), r.end());
  for (int i = 0; i < l.size() && i < r.size(); i++) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int N = 2e5 + 5;

vector<int> parent(N), sz(N);

int find_set(int u) {
  if (u == parent[u])
    return u;
  return parent[u] = find_set(parent[u]);
}

void union_sets(int u, int v) {
  u = find_set(u);
  v = find_set(v);
  if (u != v) {
    if (sz[u] > sz[v])
      swap(u, v);
    parent[u] = v;
    sz[v] += sz[u];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

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

  for (int i = 0; i <= n; i++) {
    parent[i] = i;
    sz[i] = 1;
  }

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x') {
      int u = find_set(i + 1);
      parent[i] = u;
      sz[u] += 1;
    }
  }

  int total_cnt = 0;
  vector<int> cnt(n, 0);
  for (int i = 0; i < n; i++) {
    vector<int> v;
    int j = find_set(i);
    while (j < n && v.size() < k) {
      v.push_back(j);
      j += c + 1;
      if (j < n)
        j = find_set(j);
    }

    if (v.size() == k) {
      total_cnt++;
      for (auto j : v) {
        cnt[j]++;
      }
    } else {
      break;
    }
  }

  parent.clear();
  sz.clear();
  for (int i = n - 1; i >= 0; i--) {
    parent[i] = i;
    sz[i] = 1;
  }

  for (int i = 0; i < n; i++) {
    if (s[i] == 'x') {
      int u = i - 1;
      if (u >= 0)
        u = find_set(u);
      parent[i] = u;
      if (u >= 0)
        sz[u]++;
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    vector<int> v;
    int j = (parent[i] >= 0 ? find_set(i) : parent[i]);
    while (j >= 0 && v.size() < k) {
      v.push_back(j);
      j -= c + 1;
      if (j < 0)
        break;
      j = (parent[j] >= 0 ? find_set(j) : parent[j]);
    }

    if (v.size() == k) {
      total_cnt++;
      for (auto j : v) {
        cnt[j]++;
      }
    } else {
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    if (cnt[i] == total_cnt)
      cout << i + 1 << '\\n';
  }
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int n, k, c;
bool check(string s) {
  int last_idx;
  bool first_flag = false;
  int cnt = 0;
  REP(i, n) {
    if (s[n - 1 - i] == 'o' && first_flag == 0) {
      last_idx = n - 1 - i;
      first_flag = true;
      cnt++;
    } else if (s[n - 1 - i] == 'o' && first_flag == 1) {
      if (last_idx - (n - 1 - i) > c) {
        last_idx = n - 1 - i;
        cnt++;
      }
    }
  }
  if (cnt >= k) {
    return true;
  } else {
    return false;
  }
}

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

  VI L;
  VI R;
  int idx = 0;
  bool flag = false;
  REP(i, n) {
    if (L.size() > k)
      break;
    if (s[i] == 'o' && flag == false) {
      idx = i;
      L.push_back(i);
      flag = true;
    } else if (s[i] == 'o') {
      if (i - idx > c) {
        idx = i;
        L.push_back(i);
      }
    }
  }

  reverse(s.begin(), s.end());
  flag = false;
  REP(i, n) {
    if (R.size() > k)
      break;

    if (s[i] == 'o' && flag == false) {
      idx = i;
      R.push_back(n - 1 - i);
      flag = true;
    } else if (s[i] == 'o') {
      if (i - idx > c) {
        idx = i;
        R.push_back(n - 1 - i);
      }
    }
  }
  SORT(R);

  REP(i, L.size()) {
    if (L[i] == R[i]) {
      ANS(L[i] + 1);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int n, k, c;
bool check(string s) {
  int last_idx;
  bool first_flag = false;
  int cnt = 0;
  REP(i, n) {
    if (s[n - 1 - i] == 'o' && first_flag == 0) {
      last_idx = n - 1 - i;
      first_flag = true;
      cnt++;
    } else if (s[n - 1 - i] == 'o' && first_flag == 1) {
      if (last_idx - (n - 1 - i) > c) {
        last_idx = n - 1 - i;
        cnt++;
      }
    }
  }
  if (cnt >= k) {
    return true;
  } else {
    return false;
  }
}

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

  VI v;

  REP(i, n) {
    if (s[i] == 'o') {
      v.push_back(i);
    }
  }

  REP(i, v.size()) {
    copy = s;
    copy[v[i]] = 'x';
    if (!check(copy)) {
      ANS(v[i] + 1);
    }
  }

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

// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sec second
#define fir first
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define repe(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
// #define all(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int, int>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define MOD 998244353
int n, k, c;
set<ll> st;
std::vector<ll> a, b;
void cnt(string x) {

  int g = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == 'o') {
      g++;
      a.pb(i);
      i += c;
    }
  }
  g = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (x[i] == 'o') {
      g++;
      b.pb(i);
      i -= (c);
    }
  }

  // for (auto el : st)
  // 	cout << el << endl;

  for (int i = 0; i < k; i++) {
    if (a[i] == b[k - 1 - i])
      cout << a[i] + 1 << endl;
  }
  return;
}
void solve() {
  string s;
  cin >> n >> k >> c;
  cin >> s;
  cnt(s);
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast int T;
  // cin >> T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:

// JAI SHREE RAM
#pragma GCC optimize("O3")
typedef long long int ll;
typedef unsigned long long int ull;
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define sec second
#define fir first
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define repe(i, m, n) for (ll(i) = (m); (i) < (n); (i)++)
// #define all(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int, int>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define MOD 998244353
int res[2000005] = {0};
int n, k, c;
set<ll> st;
std::vector<ll> a, b;
void cnt(string x) {

  int g = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == 'o') {
      g++;
      res[i] = 1;
      a.pb(i);
      i += c;
    }
  }
  g = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (x[i] == 'o') {
      g++;
      if (res[i])
        b.pb(i);
      st.insert(i + 1);
      i -= (c);
    }
  }

  // for (auto el : st)
  // 	cout << el << endl;

  for (int i = 0; i < k; i++) {
    if (a[i] == b[k - 1 - i])
      cout << a[i] + 1 << endl;
  }
  return;
}
void solve() {
  string s;
  cin >> n >> k >> c;
  cin >> s;
  cnt(s);
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  fast int T;
  // cin >> T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int l[200010] = {}, r[200010] = {};
bool L[200010] = {}, R[200010] = {};
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  for (int i = 0; i < n;) {
    if (i - 1 >= 0)
      l[i] = l[i - 1];
    if (s[i] == 'o') {
      L[i] = true;
      ++l[i];
      if (c == 0) {
        ++i;
        continue;
      }
      int d = 1;
      while (i + d < n and d <= c) {
        l[i + d] = l[i];
        ++d;
      }
      i = (i + d);
    } else {
      ++i;
    }
  }
  for (int i = n - 1; i >= 0;) {
    if (i + 1 < n)
      r[i] = r[i + 1];
    if (s[i] == 'o') {
      R[i] = true;
      ++r[i];
      if (c == 0) {
        --i;
        continue;
      }
      int d = 1;
      while (i - d >= 0 and d <= c) {
        r[i - d] = r[i];
        ++d;
      }
      i = (i - d);
    } else {
      --i;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (L[i])
      l[i]--;
    if (R[i])
      r[i]--;
    if (l[i] + r[i] == k - 1) {
      cout << i + 1 << '\\n';
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int l[100010] = {}, r[100010] = {};
bool L[100010] = {}, R[100010] = {};
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  for (int i = 0; i < n;) {
    if (i - 1 >= 0)
      l[i] = l[i - 1];
    if (s[i] == 'o') {
      L[i] = true;
      ++l[i];
      if (c == 0) {
        ++i;
        continue;
      }
      int d = 1;
      while (i + d < n and d <= c) {
        l[i + d] = l[i];
        ++d;
      }
      i = (i + d);
    } else {
      ++i;
    }
  }
  for (int i = n - 1; i >= 0;) {
    if (i + 1 < n)
      r[i] = r[i + 1];
    if (s[i] == 'o') {
      R[i] = true;
      ++r[i];
      if (c == 0) {
        --i;
        continue;
      }
      int d = 1;
      while (i - d >= 0 and d <= c) {
        r[i - d] = r[i];
        ++d;
      }
      i = (i - d);
    } else {
      --i;
    }
  }
  for (int i = 0; i < n; ++i) {
    // cerr << l[i] << " " << r[i] << '\\n';
    // cerr << L[i] << " " << R[i] << '\\n';
    if (L[i] and R[i]) {
      if (l[i] <= k and r[i] <= k) {
        cout << i + 1 << '\\n';
      }
    }
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

// Created by Kira

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

#define IOS                                                                    \\
  cin.sync_with_stdio(0);                                                      \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

ll n, k, c;

int main() {
  IOS

          cin >>
      n >> k >> c;

  string s = string(n + 1, ' ');
  vi L(n + 1), R(n + 1);

  for (int i = 1; i <= n; i++)
    cin >> s[i];

  int r = 1;
  for (int i = 1; i <= n and r <= k; i++) {
    if (s[i] == 'o') {
      L[r] = i, r++;
      i += c;
      if (i >= n)
        break;
    }
  }
  r = k;
  for (int i = n; i >= 1 and r >= 1; --i) {
    if (s[i] == 'o') {
      R[r] = i, r--;
      i -= c;
      if (i <= 1)
        break;
    }
  }

  for (int i = 1; i <= k; i++) {
    if (L[i] == R[i]) {
      cout << L[i] << "\\n";
    }
  }
}

ll pwr(ll a, ll b) {
  a %= mod; // Remove mod if not required
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }

  return res;
}


Error: 0

Fixed submission:

// Created by Kira

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

#define IOS                                                                    \\
  cin.sync_with_stdio(0);                                                      \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

ll n, k, c;

int main() {
  IOS

          cin >>
      n >> k >> c;

  string s = string(n + 1, ' ');
  vi L(n + 1), R(n + 1);

  for (int i = 1; i <= n; i++)
    cin >> s[i];

  int r = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] == 'o') {
      L[r] = i, r++;
      i += c;
      if (i >= n)
        break;
    }
  }
  r = k;
  for (int i = n; i >= 1; --i) {
    if (s[i] == 'o') {
      R[r] = i, r--;
      i -= c;
      if (i <= 1)
        break;
    }
  }

  for (int i = 1; i <= k; i++) {
    if (L[i] == R[i]) {
      cout << L[i] << "\\n";
    }
  }
}

ll pwr(ll a, ll b) {
  a %= mod; // Remove mod if not required
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }

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

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

int cnt[201010];
int cnt2[201010];

signed main(void) {

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

  int pos = 0;
  int work = 0;
  int num = 0;

  while (pos < n && work < k) {

    if (s[pos] == 'o' && (num >= c || work == 0)) {

      work++;
      num = 0;
      cnt[pos] = work;
    } else {
      if (work) {
        num++;
      }
    }

    pos++;
  }

  reverse(s.begin(), s.end());

  pos = 0;
  work = 0;
  num = 0;

  while (pos < n && work < k) {

    if (s[pos] == 'o' && (num >= c || work == 0)) {
      num = 0;
      work++;
      cnt2[n - pos - 1] = k - work + 1;
    } else {
      if (work) {
        num++;
      }
    }
    pos++;
  }

  for (int i = 0; i < n; i++) {
    if (cnt[i] == cnt2[i] && cnt[i] != 0) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int cnt[101010];

signed main(void) {

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

  int pos = 0;
  int work = 0;
  int num = 0;

  while (pos < n && work <= k) {

    if (s[pos] == 'o' && (num >= c || work == 0)) {
      work++;
      num = 0;
      cnt[pos]++;
    } else {
      if (work) {
        num++;
      }
    }

    pos++;
  }

  reverse(s.begin(), s.end());

  pos = 0;
  work = 0;
  num = 0;

  while (pos < n && work <= k) {

    if (s[pos] == 'o' && (num >= c || work == 0)) {
      num = 0;
      work++;
      cnt[n - pos - 1]++;
    } else {
      if (work) {
        num++;
      }
    }
    pos++;
  }

  for (int i = 0; i < n; i++) {
    if (cnt[i] == 2) {
      cout << i + 1 << endl;
    }
  }

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

#include <deque>
#include <iostream>
#include <string>

#define endl '\\n'
#define ll long long

using namespace std;

int check[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, k, c;
  string s;
  deque<int> bound;
  cin >> n >> k >> c >> s;

  int count = 0;
  for (int i = 0; i < n && count < k; i++) {
    if (s[i] == 'o') {
      check[count++] = i;
      i += c;
    }
  }

  count = k - 1;
  for (int j = n - 1; j >= 0 && count >= 0; j--) {
    if (s[j] == 'o') {
      if (check[count--] == j)
        bound.push_front(j);
      j -= c;
    }
  }

  for (auto a : bound) {
    cout << a + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <deque>
#include <iostream>
#include <string>

#define endl '\\n'
#define ll long long

using namespace std;

bool check[100000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, k, c;
  string s;
  deque<int> bound;
  cin >> n >> k >> c >> s;

  int count = k;
  for (int i = 0; i < n && count > 0; i++) {
    if (s[i] == 'o') {
      check[i] = true;
      count--;
      i += c;
    }
  }

  count = k;
  for (int j = n - 1; j >= 0 && count > 0; j--) {
    if (s[j] == 'o') {
      if (check[j] == true)
        bound.push_front(j);
      count--;
      j -= c;
    }
  }

  for (auto a : bound) {
    cout << a + 1 << endl;
  }

  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template <class T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &x : v) {
    s >> x;
  }
  return s;
}

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> f(n, -1), b(n, -1);
  for (int i = 0, cnt = 1; cnt <= k; i++) {
    if (s[i] == 'o') {
      f[i] = cnt;
      cnt++;
      i += c;
    }
  }
  for (int i = n - 1, cnt = k; cnt >= 1; i--) {
    if (s[i] == 'o') {
      b[i] = cnt;
      cnt--;
      i -= c;
    }
  }
  rep(i, n) if (f[i] != -1 && f[i] == b[i]) cout << i + 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template <class T> istream &operator>>(istream &s, vector<T> &v) {
  for (T &x : v) {
    s >> x;
  }
  return s;
}

int n, k, c;
string s;
map<int, vector<int>> able;
vector<int> memo, memo2;
map<int, int> m;
int all = 0;

void check(int date, int pre, vector<int> list) {
  list.push_back(date);
  if (pre == k) {
    for (int i : list) {
      if (m[i] == 0)
        memo2.push_back(i);
      m[i]++;
    }
    all++;
  }
  for (int i : able[date])
    if (able[date].size() + pre + 1 >= k)
      check(i, pre + 1, list);
}

int main() {
  cin >> n >> k >> c >> s;
  int size = (int)s.size();
  rep(i, size) {
    if (s[i] == 'o') {
      memo.push_back(i);
      for (int j = i + c + 1; j < size; j++)
        if (s[j] == 'o')
          able[i].push_back(j);
    }
  }
  vector<int> none;
  for (int i : memo)
    if (able[i].size() >= k - 1)
      check(i, 1, none);
  sort(memo2.begin(), memo2.end());
  for (int i : memo2)
    if (all == m[i])
      cout << i + 1 << endl;
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int n, k, c, l[200005], r[200005];
string s;

int main() {
  cin >> n >> k >> c;
  cin >> s;
  int pre = -c - 1, idx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && i - pre > c) {
      pre = i;
      l[idx] = i;
      idx++;
      if (idx == k)
        break;
    }
  }
  pre = n + c, idx = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o' && pre - i > c) {
      pre = i;
      r[idx] = i;
      idx--;
      if (idx == -1)
        break;
    }
  }
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i])
      cout << l[i] + 1 << "\\n";
  }
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int n, k, c, l[200005], r[200005];
string s;

int main() {
  cin >> n >> k >> c;
  cin >> s;
  int pre = -c - 1, idx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && i - pre > c) {
      pre = i;
      l[idx] = i;
      idx++;
      if (idx == k)
        break;
    }
  }
  pre = n + c, idx = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o' && pre - i > c) {
      pre = i;
      r[idx] = i;
      idx--;
      if (idx == 0)
        break;
    }
  }
  for (int i = 0; i < k; i++) {
    if (l[i] == r[i])
      cout << l[i] << "\\n";
  }
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  ll n, k, c;
  string s;

  cin >> n >> k >> c >> s;

  deque<int> l, r;

  ll count = 1;

  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      l.push_back(i);
      count++;

      if (count > k) {
        break;
      }

      i += c;
    }
  }

  count = 1;

  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      r.push_front(i);
      count++;

      if (count > k) {
        break;
      }

      i -= c;
    }
  }

  count = 1;

  for (int i = 0; i < k; i++) {

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {
  ll n, k, c;
  string s;

  cin >> n >> k >> c >> s;

  vector<int> l, r;

  ll count = 1;

  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      l.push_back(i);
      count++;

      if (count > k) {
        break;
      }

      i += c;
    }
  }

  count = 1;

  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      r.insert(r.begin(), i);
      count++;

      if (count > k) {
        break;
      }

      i -= c;
    }
  }

  count = 1;

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

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N];
int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  for (int i = 0, id = 0; i < n; i++)
    if (s[i] == 'o')
      a[id++] = i, i += c;
  for (int i = n - 1, id = k - 1; i >= 0 && id >= 0; i--)
    if (s[i] == 'o')
      b[id--] = i, i -= c;
  for (int i = 0; i < k; i++)
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

string str;
int N, K, C, l, F, workday;
int W2[200005];
int W1[200005];

void work(int day, int free) {
  if (workday < K) {
    if (day > N)
      return;
  } else {
    for (int i = 1; i <= day; i++) {
      W2[W1[i]]++;
    }
    F++;
    return;
  }

  if (free <= 0) {
    if (str[day - 1] == 'o') {
      workday++;
      W1[workday] = day;
      work(day + 1, C);
      W1[workday] = 0;
      workday--;
      work(day + 1, 0);
    }
    work(day + 1, free - 1);
  } else {
    work(day + 1, free - 1);
  }
  return;
}

int main() {
  cin >> N >> K >> C >> str;
  work(1, 0);
  for (int i = 1; i <= N; i++) {
    if (W2[i] == F)
      cout << i << endl;
  }
  return 0;
}