Problem p01418 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cout << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 1120000000
#define EPS 1e-10

int main() {
  int k;
  double r, l, po, e, t;
  cin >> k >> l >> r >> po >> e >> t;

  double ans = 0;
  using Map = map<pair<double, double>, double>;
  Map m;
  m[mp(l, r)] = 1;
  rep(i, k) {
    Map nxt;
    for (auto p : m) {
      double cl = p.fi.fi, cr = p.fi.se;
      if (t - e - EPS <= cl && cr <= t + e + EPS) {
        ans += p.se;
        continue;
      }
      if (t + e < cl || cr < t - e)
        continue;
      double cm = (cl + cr) / 2;
      if (t <= cm) {
        if (1.0 - po > EPS)
          nxt[mp(cl, cm)] += p.se * (1.0 - po);
        if (po > EPS)
          nxt[mp(cm, cr)] += p.se * po;
      } else {
        if (po > EPS)
          nxt[mp(cl, cm)] += p.se * po;
        if (1.0 - po > EPS)
          nxt[mp(cm, cr)] += p.se * (1.0 - po);
      }
    }
    swap(nxt, m);
  }
  for (auto p : m) {
    double mid = (p.fi.fi + p.fi.se) / 2.0;
    if (t - e - EPS <= mid && mid <= t + e + EPS) {
      ans += p.se;
    }
  }

  printf("%.9f\\n", ans);

  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cout << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
  int l = s.find(',');
  cout << s.substr(0, l) << " = " << h << ", ";
  _dbg(s.substr(l + 1), t...);
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 1120000000
#define EPS 1e-10

int main() {
  int k;
  double r, l, po, e, t;
  cin >> k >> l >> r >> po >> e >> t;

  double ans = 0;
  using Map = map<pair<double, double>, double>;
  Map m;
  m[mp(l, r)] = 1;
  rep(i, k) {
    Map nxt;
    for (auto p : m) {
      double cl = p.fi.fi, cr = p.fi.se;
      if (t - e - EPS <= cl && cr <= t + e + EPS) {
        ans += p.se;
        continue;
      }
      if (t + e < cl || cr < cr)
        continue;
      double cm = (cl + cr) / 2;
      if (cl <= t && t <= cm) {
        if (1.0 - po > EPS)
          nxt[mp(cl, cm)] += p.se * (1.0 - po);
        if (po > EPS)
          nxt[mp(cm, cr)] += p.se * po;
      } else {
        if (po > EPS)
          nxt[mp(cl, cm)] += p.se * po;
        if (1.0 - po > EPS)
          nxt[mp(cm, cr)] += p.se * (1.0 - po);
      }
    }
    swap(nxt, m);
  }
  for (auto p : m) {
    double mid = (p.fi.fi + p.fi.se) / 2.0;
    if (t - e - EPS <= mid && mid <= t + e + EPS) {
      ans += p.se;
    }
  }

  printf("%.9f\\n", ans);

  return 0;
}