Problem p02721 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long, long long> ii;
typedef complex<long double> com;

ll mod = 1e9 + 7;

ll k;

vector<vector<ll>> graph;
vector<vector<ll>> depth;
vector<bool> visited;

void dfs(ll u = 1, ll d = k, ll p = -1) {
  if (visited[u])
    return;
  visited[u] = true;
  if (depth[d].size() <= 1)
    depth[d].push_back(u);
  for (ll v : graph[u]) {
    if (v == p)
      continue;
    if (visited[v])
      continue;
    dfs(v, d - 1, u);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  ll current = 0;
  vector<ll> lol;
  vector<ll> value(n);
  graph.resize(n);
  depth.resize(k + 1);
  visited.resize(n, false);
  for (int z = n - 1; z >= 0; z--) {
    if (z + c + 1 <= n - 1 && s[z + c + 1] != 'x') {
      if (value[z + c + 1] > current) {
        current = value[z + c + 1];
        lol.clear();
        lol.push_back(z + c + 1);
      } else
        lol.push_back(z + c + 1);
    }
    if (s[z] == 'x')
      continue;
    for (int x = 0; x < lol.size(); x++) {
      graph[z].push_back(lol[x]);
    }
    value[z] = current + 1;
  }
  for (int z = 0; z < n; z++) {
    if (value[z] > k)
      return 0;
  }
  for (int z = 0; z < n; z++) {
    if (visited[z])
      continue;
    if (value[z] == k) {
      dfs(z);
    }
  }
  set<ll> ans;
  for (int z = 0; z <= k; z++) {
    if (depth[z].size() == 1) {
      ans.insert(depth[z][0]);
    }
  }
  for (ll i : ans) {
    cout << i + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC omodtimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long, long long> ii;
typedef complex<long double> com;

ll mod = 1e9 + 7;

ll k;

vector<vector<ll>> graph;
vector<vector<ll>> depth;
vector<bool> visited;

void dfs(ll u = 1, ll d = k, ll p = -1) {
  if (visited[u])
    return;
  visited[u] = true;
  if (depth[d].size() <= 1)
    depth[d].push_back(u);
  for (ll v : graph[u]) {
    if (v == p)
      continue;
    if (visited[v])
      continue;
    dfs(v, d - 1, u);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  ll current = 0;
  vector<ll> lol;
  vector<ll> value(n);
  graph.resize(n);
  depth.resize(k + 1);
  visited.resize(n, false);
  for (int z = n - 1; z >= 0; z--) {
    if (z + c + 1 <= n - 1 && s[z + c + 1] != 'x') {
      if (value[z + c + 1] > current) {
        current = value[z + c + 1];
        lol.clear();
        lol.push_back(z + c + 1);
      } else
        lol.push_back(z + c + 1);
    }
    if (s[z] == 'x')
      continue;
    for (int x = 0; x < min(10, int(lol.size())); x++) {
      graph[z].push_back(lol[x]);
    }
    value[z] = current + 1;
  }
  for (int z = 0; z < n; z++) {
    if (value[z] > k)
      return 0;
  }
  for (int z = 0; z < n; z++) {
    if (visited[z])
      continue;
    if (value[z] == k) {
      dfs(z);
    }
  }
  set<ll> ans;
  for (int z = 0; z <= k; z++) {
    if (depth[z].size() == 1) {
      ans.insert(depth[z][0]);
    }
  }
  for (ll i : ans) {
    cout << i + 1 << endl;
  }
}