alexjercan/bugnet huggingface dataset:
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;
using ll = long long;
using P = pair<int, int>;
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
void debug_out() { cout << "\\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &...args) {
  cout << x << " ";
  debug_out(args...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> L(k + 1, -1), R(k + 1, -1);
  int cnt = 1;
  rep(i, n) {
    if (s[i] == 'o') {
      L[cnt++] = i + 1;
      i += c;
    }
    if (cnt == k + 1)
      break;
  }
  cnt = k;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      R[cnt--] = i + 1;
      i -= c;
    }
    if (cnt == 0)
      break;
  }
  for (int i = 1; i <= k; ++i) {
    if (L[i] == R[i] && L[i] != -1)
      cout << L[i] << "\\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;
using ll = long long;
using P = pair<int, int>;
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
void debug_out() { cout << "\\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &...args) {
  cout << x << " ";
  debug_out(args...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> L(k + 1, -1), R(k + 1, -1);
  int cnt = 1;
  rep(i, n) {
    if (s[i] == 'o') {
      L[cnt++] = i + 1;
      i += c;
    }
  }
  cnt = k;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      R[cnt--] = i + 1;
      i -= c;
    }
  }
  for (int i = 1; i <= k; ++i) {
    if (L[i] == R[i] && L[i] != -1)
      cout << L[i] << "\\n";
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> L(k), R(k);
  for (int i = 0, cnt = 0; i < n && cnt < k;) {
    if (s[i] == 'o') {
      L[cnt] = (i + 1);
      i += (c + 1);
      cnt++;
    } else {
      i++;
    }
  }
  reverse(s.begin(), s.end());
  for (int i = 0, cnt = 0; i < n && cnt < k;) {
    if (s[i] == 'o') {
      R[k - 1 - cnt] = n - i;
      i += (c + 1);
      cnt++;
    } else {
      i++;
    }
  }
  rep(i, k) {
    if (L[i] == R[i]) {
      cout << L[i] << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  queue<int> q;
  int i = 0;
  while (q.size() < k) {
    if (s[i] == 'o') {
      q.push(i);
      i += (c + 1);
    } else if (i > n) {
      return 0;
    } else {
      i++;
    }
  }
  int b = q.front();
  rep(i, k) {
    int a = q.front();
    q.pop();
    int C = 0;
    if (a == b) {
      for (int i = a + 1; i < n && C < k;) {
        if (s[i] == 'o') {
          i += (c + 1);
          C++;
        } else {
          i++;
        }
      }
      if (C < k) {
        q.push(a);
      }

    } else {
      for (int i = b; i < n && C < k;) {
        if (i == a) {
          i++;
        } else if (s[i] == 'o') {
          i += (c + 1);
          C++;
        } else {
          i++;
        }
      }
      if (C < k) {
        q.push(a);
      }
    }
  }
  while (!q.empty()) {
    cout << (q.front() + 1) << endl;
    q.pop();
  }
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\\n" : "NO\\n")
#define Yes(n) cout << ((n) ? "Yes\\n" : "No\\n")
#define POSSIBLE cout << ((n) ? "POSSIBLE\\n" : "IMPOSSIBLE\\n")
#define ANS(n) cout << (n) << "\\n"
#define REP(i, n) for (int64 i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define FORR(i, a, b) for (int64 i = (a); i >= (b); i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define pii pair<int32, int32>
#define pll pair<int64, int64>
#define pb(a) push_back(a)
#define mp make_pair

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int32> l(k + 1, -1), r(k + 1, -1);
  int32 cnt = 0;
  REP(i, n) {
    if (s[i] == 'o') {
      cnt++;
      if (cnt > k)
        break;
      l[cnt] = i;
      i += c;
    }
  }
  cnt = 0;
  FORR(i, n - 1, 0) {
    if (s[i] == 'o') {
      cnt++;
      if (cnt > k)
        break;
      r[cnt] = i;
      i -= c;
    }
  }
  // REP(i,k+1){
  //   cout << l[i] << " " << r[i] << endl;
  // }
  FOR(i, 1, k + 1) {
    if (l[i] == r[k + 1 - i]) {
      ANS(l[i] + 1);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\\n" : "NO\\n")
#define Yes(n) cout << ((n) ? "Yes\\n" : "No\\n")
#define ANS(n) cout << (n) << "\\n"
#define REP(i, n) for (int64 i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define FORR(i, a, b) for (int64 i = (a); i >= (b); i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define pii pair<int32, int32>
#define pll pair<int64, int64>
#define pb(a) push_back(a)
#define mp make_pair

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int32> o;
  REP(i, n) {
    if (s[i] == 'o')
      o.emplace_back(i);
  }
  vector<vector<int32>> nx(n);
  // Yes(lower_bound(ALL(o),1000) != o.end());
  REP(i, o.size()) {
    auto x = lower_bound(ALL(o), o[i] + c + 1);
    if (x - o.begin() < o.size()) {
      nx[o[i]].pb(*x);
    }
    ++x;
    if (x - o.begin() < o.size()) {
      nx[o[i]].pb(*x);
    }
  }
  // REP(i,n){
  //   cout << i << " ";
  //   for(int32 nxi : nx[i]){
  //     cout << nxi << " ";
  //   }
  //   cout << endl;
  // }
  if (o.size() == 1) {
    ANS(1);
    return 0;
  }
  REP(i, o.size()) {
    int32 cnt = 1;
    int32 cur = o[0];
    if (i == 0)
      cur = o[1];
    while (nx[cur].size() != 0) {
      if (nx[cur][0] != o[i]) {
        cur = nx[cur][0];
        cnt++;
      } else {
        if (nx[cur].size() == 1)
          break;
        cur = nx[cur][1];
        cnt++;
      }
    }
    // cout << cnt << " " << o[i]+1 << endl;
    if (cnt < k) {
      cout << o[i] + 1 << endl;
    }
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> bef(n), aft(n);
  int pos = 0;
  for (int i = 0; i < k; i++) {
    while (s[pos] != 'o')
      pos++;
    bef[pos] = i + 1;
    pos += c + 1;
  }
  pos = n - 1;
  for (int i = 0; i < k; i++) {
    while (s[pos] != 'o')
      pos--;
    aft[pos] = k - i;
    pos -= c + 1;
  }
  for (int i = 0; i < n; i++) {
    if (bef[i] == aft[i] && bef[i])
      cout << i + 1 << "\\n";
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

bool possible(int k, int c, string &s) {
  int day = 0;
  while ((day = s.find_first_of("o", day)) != std::string::npos) {
    day += c + 1;
    if (!--k)
      return true;
  }

  return false;
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, c;
  string s;
  cin >> n >> k >> c;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      s[i] = 'x';
      if (!possible(k, c, s))
        cout << i + 1 << endl;
      s[i] = 'o';
    }
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define print(n) cout << n << endl

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

  ll n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<ll> f(k);
  vector<ll> r(k);
  int x = 0;
  rep(i, n) {
    if (s[i] == 'o') {
      f[x] = i;
      i += c;
      x++;
      if (x >= k)
        break;
    }
  }
  x = k - 1;
  rrep(i, n) {
    if (s[i - 1] == 'o') {
      r[x] = i - 1;
      i -= c;
      x--;
      if (x < 0)
        break;
    }
  }
  rep(i, k) if (f[i] == r[i]) print(f[i] + 1);

  return 0;
}

Error: 0

Fixed submission:

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

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define print(n) cout << n << endl

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

  ll n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<ll> f(k);
  vector<ll> r(k);
  int x = 0;
  rep(i, n) {
    if (s[i] == 'o') {
      f[x] = i;
      i += c;
      x++;
    }
  }
  x = k - 1;
  rrep(i, n) {
    if (s[i] == 'o') {
      r[x] = i;
      i -= c;
      x--;
    }
  }
  rep(i, k) if (f[i] == r[i]) print(f[i] + 1);
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int a[200000];
  int b[200000];
  for (int i = 0, cur = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[cur++] = i;
      i += c;
    }
  }
  for (int i = n - 1, cur = k - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b[cur--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++) {
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  }
}

Error: 0

Fixed submission:

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

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

#include <algorithm>
#include <iostream>
#include <vector>
int main() {
  int N, K, C;
  std::cin >> N >> K >> C;
  std::string s;
  std::cin >> s;
  std::vector<int> front(K);
  std::vector<int> back(K);
  int farthest_front, farthest_back;
  int count_front = -1, count_back = K;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'o')
      if (count_front == -1 || (i - farthest_front) > C) {
        if (++count_front >= K)
          return 0;
        front[count_front] = i + 1;
        farthest_front = i;
      }
    if (s[N - i - 1] == 'o')
      if (count_back == K || (i - farthest_back) > C) {
        if (--count_back < 0)
          return 0;
        back[count_back] = N - i;
        farthest_back = i;
      }
  }
  for (int i = 0; i < K; i++)
    if (front[i] == back[i])
      std::cout << front[i] << std::endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
int main() {
  int N, K, C;
  std::cin >> N >> K >> C;
  std::string s;
  std::cin >> s;
  std::vector<int> front(N);
  std::vector<int> back(N);
  int farthest_front, farthest_back;
  int count_front = -1, count_back = K;
  for (int i = 0; i < N; i++) {
    if (s[i] == 'o')
      if (count_front == -1 || (i - farthest_front) > C) {
        if (++count_front >= K)
          return 0;
        farthest_front = i;
      }
    front[i] = count_front;
    if (s[N - i + 1] == 'o')
      if (count_back == K || (i - farthest_back) > C) {
        if (--count_back < 0)
          return 0;
        farthest_back = i;
      }
    back[N - i + 1] = count_back;
  }
  int n_match, last_match, prev = -1;
  for (int i = 0; i < N; i++) {
    if (front[i] != prev) {
      if (n_match == 1)
        std::cout << last_match << std::endl;
      n_match = 0;
    }
    if (front[i] == back[i]) {
      n_match++;
      last_match = i + 1;
    }
    prev = front[i];
  }
  if (n_match == 1)
    std::cout << last_match << std::endl;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define PB(x) push_back(x)

int main(int argc, char **argv) {

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

  vi l(k);
  vi r(k);

  int cc = 0;

  int kc = 0;
  REP(i, 0, n - 1 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      l[kc] = i;
      ++kc;
      cc = c;
    }
  }

  kc = k - 1;
  cc = 0;
  RREP(i, n - 1, 0 && kc >= 0) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      r[kc] = i;
      kc--;
      cc = c;
    }
  }

  REP(i, 0, k - 1) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define PB(x) push_back(x)

int main(int argc, char **argv) {

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

  vi l(k);
  vi r(k);

  int cc = 0;

  int kc = 0;
  REP(i, 0, n - 1 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      l[kc] = i;
      ++kc;
      cc = c;
    }
  }

  kc = k - 1;
  cc = 0;
  RREP(i, n - 1, 0 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      r[kc] = i;
      kc--;
      cc = c;
    }
  }

  REP(i, 0, k - 1) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  }
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int n, k, c, a, b;
vector<int> v1, v2;
string s;
int main() {
  cin >> n >> k >> c >> s;
  a = -1e9, b = 1e9;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o' && a + c < i) {
      a = i;
      v1.push_back(i);
    }
    if (v1.size() == k)
      break;
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o' && b >= c) {
      b = 0;
      v2.push_back(i);
    } else
      ++b;
    if (v2.size() == k)
      break;
  }
  reverse(v2.begin(), v2.end());
  for (int i = 0; i < k; ++i)
    if (v1[i] == v2[i])
      cout << v1[i] + 1 << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n, k, c, a, b;
vector<int> v1, v2;
string s;
int main() {
  cin >> n >> k >> c >> s;
  a = -1e9, b = 1e9;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'o' && a + c < i) {
      a = i;
      v1.push_back(i);
    }
    if (v1.size() == k)
      break;
  }
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i] == 'o' && b > c) {
      b = 0;
      v2.push_back(i);
    } else
      ++b;
    if (v2.size() == k)
      break;
  }
  reverse(v2.begin(), v2.end());
  for (int i = 0; i < k; ++i)
    if (v1[i] == v2[i])
      cout << v1[i] + 1;
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000;
int n, k, c;
string s;
int main() {
  cin >> n >> k >> c >> s;
  vector<int> g1(k), g2(k);
  {
    int lst = -inf;
    int p = 0;
    for (int i = 0; i < n && p < k; ++i) {
      if (s[i] == 'o' && i > lst + c) {
        g1[p++] = i;
        lst = i;
      }
    }
  }
  {
    int lst = inf;
    int p = k - 1;
    for (int i = n - 1; i >= 0 && p >= 0; --i) {
      if (s[i] == 'o' && i < lst - c) {
        g2[p--] = i;
        lst = i;
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    if (g1[i] == g2[i]) {
      cout << g1[i] + 1 << '\\n';
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000;
int n, k, c;
string s;
int main() {
  cin >> n >> k >> c >> s;
  vector<int> g1, g2;
  {
    int lst = -inf;
    int p = 0;
    for (int i = 0; i < n && p < k; ++i) {
      if (s[i] == 'o' && i > lst + c) {
        g1[p++] = i;
        lst = i;
      }
    }
  }
  {
    int lst = inf;
    int p = k - 1;
    for (int i = n - 1; i >= 0 && p >= 0; --i) {
      if (s[i] == 'o' && i < lst - c) {
        g2[p--] = i;
        lst = i;
      }
    }
  }
  for (int i = 0; i < k; ++i) {
    if (g1[i] == g2[i]) {
      cout << g1[i] + 1 << '\\n';
    }
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;
  vector<int> L(K);
  vector<int> B(K);

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'o') {
      L.at(cnt) = i;
      cnt++;
      i += C;
    }
    if (cnt >= K) {
      break;
    }
  }
  cnt = K - 1;
  for (int i = 0; i < N; i++) {
    if (S.at(N - i - 1) == 'o') {
      B.at(cnt) = N - i - 1;
      cnt--;
      i += C;
    }
    if (cnt < 0) {
      break;
    }
  }
  for (int i = 0; i < K; i++) {
    if (L.at(i) == B.at(i)) {
      cout << L.at(i) + 1 << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;
  vector<int> L(K);
  vector<int> B(K);

  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'o') {
      L.at(cnt) = i;
      cnt++;
      i += C;
    }
  }
  cnt = K - 1;
  for (int i = 0; i < N; i++) {
    if (S.at(N - i - 1) == 'o') {
      B.at(cnt) = N - i - 1;
      cnt--;
      i += C;
    }
  }
  for (int i = 0; i < K; i++) {
    if (L.at(i) == B.at(i)) {
      cout << L.at(i) + 1 << endl;
    }
  }
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

// editorial
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> r(n, -1), l(n, -1);
  int tim = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x')
      continue;
    r[tim++] = i;
    i += c;
  }
  tim = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x')
      continue;
    l[tim--] = i;
    if (tim < 0)
      break;
    i -= c;
  }
  for (int i = 0; i < k; i++) {
    if (r[i] == l[i])
      cout << r[i] + 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// editorial
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> r(n), l(n);
  int tim = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x')
      continue;
    r[tim++] = i;
    i += c;
  }
  tim = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x')
      continue;
    l[tim--] = i;
    i -= c;
  }
  for (int i = 0; i < k; i++) {
    if (r[i] == l[i])
      cout << r[i] + 1 << endl;
  }
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
int n, k, c, f[200003][2];
char s[200003];
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);
  int i, j = 0;
  for (i = 1; i <= n; i++) {
    if (s[i] == 'o' && i > j)
      f[i][0] = f[i - 1][0] + 1, j = i + c;
    else
      f[i][0] = f[i - 1][0];
  }
  j = n + 1;
  for (i = n; i >= 1; i--) {
    if (s[i] == 'o' && i < j)
      f[i][1] = f[i + 1][1] + 1, j = i - c;
    else
      f[i][1] = f[i + 1][1];
  }
  for (int i = 1; i <= n; i++)
    if (f[i - 1][0] + 1 + f[i + 1][1] == k)
      printf("%d\\n", i);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
int n, k, c, f[100003][2];
char s[200003];
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);
  int i, j = 0;
  for (i = 1; i <= n; i++) {
    if (s[i] == 'o' && i > j)
      f[i][0] = f[i - 1][0] + 1, j = i + c;
    else
      f[i][0] = f[i - 1][0];
  }
  j = n + 1;
  for (i = n; i >= 1; i--) {
    if (s[i] == 'o' && i < j)
      f[i][1] = f[i + 1][1] + 1, j = i - c;
    else
      f[i][1] = f[i + 1][1];
  }
  for (int i = 1; i <= n; i++)
    if (f[i - 1][0] + 1 + f[i + 1][1] == k)
      printf("%d\\n", i);
  return 0;
}
Problem p02721 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int N, K, C;

int main() {
  cin >> N >> K >> C;
  vector<int> workday;

  for (int i = 0; i < N; i++) {
    char s;
    cin >> s;

    if (s == 'o') {
      workday.push_back(i);
    }
  }

  vector<int> af;

  int temp = 0;
  int day = 0;

  temp = N - 1;
  day = K;
  for (int i = (int)workday.size() - 1; i >= 0; i--) {
    if (temp >= workday[i]) {
      af.push_back(workday[i]);
      temp = workday[i] - C - 1;
      day--;
    }
    if (day == 0) {
      break;
    }
  }

  temp = 0;
  day = 0;

  for (int i = 0; i < workday.size(); i++) {
    if (temp <= workday[i]) {
      if (workday[i] == af[K - 1 - day]) {
        cout << af[K - 1 - day] + 1 << endl;
      }
      temp = workday[i] + C + 1;
      day++;
    }
    if (day == K) {
      break;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int N, K, C;

int main() {
  cin >> N >> K >> C;
  vector<int> workday;

  for (int i = 0; i < N; i++) {
    char s;
    cin >> s;

    if (s == 'o') {
      workday.push_back(i);
    }
  }

  vector<int> af;

  int temp = 0;
  int day = 0;

  temp = N - 1;
  day = K;
  for (int i = (int)workday.size() - 1; i >= 0; i--) {
    if (temp >= workday[i]) {
      af.insert(af.begin(), workday[i]);
      temp = workday[i] - C - 1;
      day--;
    }
    if (day == 0) {
      break;
    }
  }

  temp = 0;
  day = 0;

  for (int i = 0; i < workday.size(); i++) {
    if (temp <= workday[i]) {
      if (workday[i] == af[day]) {
        cout << af[day] + 1 << endl;
      }
      temp = workday[i] + C + 1;
      day++;
    }
    if (day == K) {
      break;
    }
  }

  return 0;
}