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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int K;
double R, L;
double P, E, T;

#define EPS (1e-5)

typedef long long ll;

double solve(int const kcnt, double ll, double rr, double prob) {

  if (T + E < ll || rr + E < T)
    return 0.;
  if (abs(ll - T) <= E && abs(rr - T) <= E)
    return prob;
  // if(prob*pow(max(1.-P, P), K-kcnt)*pow(2., K) < EPS) return 0.;
  // if(prob*pow(max(1.-P, P), K-kcnt) < EPS) return 0.;

  double H = (ll + rr) / 2.;

  if (kcnt == K) {
    if (abs(H - T) <= E) {
      return prob;
    } else {
      return 0.;
    }
  }

  // step 3.
  double ret = 0.;
  if (H <= T) {
    ret += solve(kcnt + 1, H, rr, prob * (1. - P));
    ret += solve(kcnt + 1, ll, H, prob * P);
  } else {
    ret += solve(kcnt + 1, ll, H, prob * (1. - P));
    ret += solve(kcnt + 1, H, rr, prob * P);
  }

  return ret;
}

int main() {

  cin >> K >> L >> R;
  cin >> P >> E >> T;

  printf("%.7f\\n", solve(0, L, R, 1.));

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int K;
double R, L;
double P, E, T;

#define EPS (1e-5)

typedef long long ll;

double solve(int const kcnt, double ll, double rr, double prob) {

  if (T + E + EPS < ll || rr + E + EPS < T)
    return 0.;

  double H = (ll + rr) / 2.;

  if (kcnt == K) {
    if (abs(H - T) <= E) {
      return prob;
    } else {
      return 0.;
    }
  }

  // step 3.
  double ret = 0.;
  if (H <= T) {
    ret += solve(kcnt + 1, H, rr, prob * (1. - P));
    ret += solve(kcnt + 1, ll, H, prob * P);
  } else {
    ret += solve(kcnt + 1, ll, H, prob * (1. - P));
    ret += solve(kcnt + 1, H, rr, prob * P);
  }

  return ret;
}

int main() {

  cin >> K >> L >> R;
  cin >> P >> E >> T;

  printf("%.7f\\n", solve(0, L, R, 1.));

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

const double eps = 1e-11;

int K, R, L;
double P, E, T;

bool equals(double a, double b) { return abs(a - b) < eps; }

double rec(double r, double l, int k, int flag) {
  if (flag) {
    double dist = min(abs(T - r), abs(T - l));
    if (!equals(dist, E) && dist > E)
      return 0.0;
  }

  {
    double tr = T - E;
    double tl = T + E;
    if ((equals(tr, r) || tr < r) && (equals(l, tl) || l < tl)) {
      return 1.0;
    }
  }

  if (k == 0) {
    double t = (r + l) / 2.0;
    double diff = abs(T - t);
    return (equals(diff, E) || diff < E) ? 1.0 : 0.0;
  } else {
    double h = (r + l) / 2.0;
    if (equals(h, T) || h > T) {
      return (1 - P) * rec(r, h, k - 1, 0) + P * rec(h, l, k - 1, 1);
    } else {
      return (1 - P) * rec(h, l, k - 1, 0) + P * rec(r, h, k - 1, 1);
    }
  }
}

int main() {
  cin >> K >> R >> L;
  cin >> P;
  cin >> E;
  cin >> T;
  printf("%.10f\\n", rec(R, L, K, 0));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

const double eps = 1e-11;

int K, R, L;
double P, E, T;

bool equals(double a, double b) { return abs(a - b) < eps; }

double rec(double r, double l, int k, int flag) {
  if (flag) {
    double dist = min(abs(T - r), abs(T - l));
    if (!equals(dist, E) && dist > E)
      return 0.0;
  }

  if (k == 0) {
    double t = (r + l) / 2.0;
    double diff = abs(T - t);
    return (equals(diff, E) || diff < E) ? 1.0 : 0.0;
  } else {
    double h = (r + l) / 2.0;
    if (equals(h, T) || h > T) {
      return (1 - P) * rec(r, h, k - 1, 0) + P * rec(h, l, k - 1, 1);
    } else {
      return (1 - P) * rec(h, l, k - 1, 0) + P * rec(r, h, k - 1, 1);
    }
  }
}

int main() {
  cin >> K >> R >> L;
  cin >> P;
  cin >> E;
  cin >> T;
  printf("%.10f\\n", rec(R, L, K, 0));
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int k;
double p, e, t;

double ans = 0;

void dfs(double l, double r, int cnt, double x) {
  if (r < t - e)
    return;
  if (l > t + e)
    return;

  double h = (l + r) / 2;

  if (cnt == k) {
    if (t - e <= h && h <= t + e)
      ans += x;
    return;
  }

  if (h >= t) {
    dfs(l, h, cnt + 1, (1.0 - p) * x);
    dfs(h, r, cnt + 1, p * x);
  } else {
    dfs(h, r, cnt + 1, (1.0 - p) * x);
    dfs(l, h, cnt + 1, p * x);
  }
}

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

  dfs(l, r, 0, 1.0);

  cout << fixed;
  cout.precision(20);
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int k;
double p, e, t;

double ans = 0;

void dfs(double l, double r, int cnt, double x) {
  double h = (l + r) / 2;

  if (cnt == k) {
    if (t - e <= h && h <= t + e)
      ans += x;
    return;
  }

  if (h >= t) {
    dfs(l, h, cnt + 1, (1.0 - p) * x);
    dfs(h, r, cnt + 1, p * x);
  } else {
    dfs(h, r, cnt + 1, (1.0 - p) * x);
    dfs(l, h, cnt + 1, p * x);
  }
}

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

  dfs(l, r, 0, 1.0);

  cout << fixed;
  cout.precision(20);
  cout << ans << endl;

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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;

int K, R, L;
double P, E, T;

inline double dfs(int depth, double r, double l) {
  // cout<<string(depth,'\\t');printf("%.8f %.8f\\n",l,r);
  if (depth == K) {
    // string(depth,'\\t');printf("%.8f %d\\n",(l+r)/2,abs(T-(l+r)/2)<=E);
    return 1.0 * (abs(T - (l + r) / 2) <= E);
  }
  double h = (l + r) / 2;

  if (l < T - E)
    return 0;
  if (r > T + E)
    return 0;

  double ret = 0.0;
  if (h >= T) {
    ret += dfs(depth + 1, r, h) * (1 - P);
    ret += dfs(depth + 1, h, l) * (P);
  } else {
    ret += dfs(depth + 1, r, h) * (P);
    ret += dfs(depth + 1, h, l) * (1 - P);
  }

  return ret;
}

int main() {
  cin >> K >> R >> L;
  cin >> P >> E >> T;

  printf("%.20f\\n", dfs(0, R, L));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;

int K, R, L;
double P, E, T;

double dfs(int depth, double r, double l) {
  // cout<<string(depth,'\\t');printf("%.8f %.8f\\n",l,r);
  if (depth == K) {
    // string(depth,'\\t');printf("%.8f %d\\n",(l+r)/2,abs(T-(l+r)/2)<=E);
    return 1.0 * (abs(T - (l + r) / 2) <= E);
  }
  double h = (l + r) / 2;

  if (l < T - E)
    return 0;
  if (r > T + E)
    return 0;

  double ret = 0.0;
  if (h >= T) {
    ret += dfs(depth + 1, r, h) * (1 - P);
    ret += dfs(depth + 1, h, l) * (P);
  } else {
    ret += dfs(depth + 1, r, h) * (P);
    ret += dfs(depth + 1, h, l) * (1 - P);
  }

  return ret;
}

int main() {
  cin >> K >> R >> L;
  cin >> P >> E >> T;

  printf("%.20f\\n", dfs(0, R, L));
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int k, r, l;
double p, e, t;

double rec(int depth, double l, double r) {
  //    printf("%d %lf %lf\\n", depth, l, r);
  double mid = (l + r) / 2, ret = 0;
  if (depth == k) {
    if (mid >= t - e && mid <= t + e)
      return 1;
    return 0;
  }

  if (r + e < t || l - e > t)
    return 0;
  if (r < t + e && l > t - e)
    return 1;

  if (mid > t) {
    ret += (1 - p) * rec(depth + 1, l, mid);
    ret += p * rec(depth + 1, mid, r);
  } else {
    ret += p * rec(depth + 1, l, mid);
    ret += (1 - p) * rec(depth + 1, mid, r);
  }
  return ret;
}

int main() {
  scanf("%d %d %d %lf %lf %lf", &k, &l, &r, &p, &e, &t);
  printf("%.12f\\n", rec(0, l, r));
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int k, r, l;
double p, e, t;

double rec(int depth, double l, double r) {
  //    printf("%d %lf %lf\\n", depth, l, r);
  double mid = (l + r) / 2, ret = 0;
  if (depth == k) {
    if (mid >= t - e && mid <= t + e)
      return 1;
    return 0;
  }

  if (r + e < t || l - e > t)
    return 0;

  if (mid > t) {
    ret += (1 - p) * rec(depth + 1, l, mid);
    ret += p * rec(depth + 1, mid, r);
  } else {
    ret += p * rec(depth + 1, l, mid);
    ret += (1 - p) * rec(depth + 1, mid, r);
  }
  return ret;
}

int main() {
  scanf("%d %d %d %lf %lf %lf", &k, &l, &r, &p, &e, &t);
  printf("%.12f\\n", rec(0, l, r));
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

double P, E, T;

double solve(double L, double R, int K) {
  double H = (L + R) / 2.0;
  if (K == 0) {
    if (T - E <= H && H <= T + E) {
      return 1;
    } else {
      return 0;
    }
  }

  if (T - E <= L && L <= T + E && T - E <= R && R <= T + E) {
    return 1;
  }

  if (T - E > L || T + E < R) {
    return 0;
  }

  double res = 0;
  if (H < T) {
    res += solve(L, H, K - 1) * (1 - P);
    res += solve(H, R, K - 1) * P;
  } else {
    res += solve(H, R, K - 1) * (1 - P);
    res += solve(L, H, K - 1) * P;
  }
  return res;
}

int main() {
  int K;
  double R, L;
  cin >> K >> R >> L >> P >> E >> T;
  printf("%.8f\\n", solve(L, R, K));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

double P, E, T;

double solve(double L, double R, int K) {
  double H = (L + R) / 2.0;
  if (K == 0) {
    if (T - E <= H && H <= T + E) {
      return 1;
    } else {
      return 0;
    }
  }

  if (T - E > L || T + E < R) {
    return 0;
  }

  double res = 0;
  if (H < T) {
    res += solve(L, H, K - 1) * (1 - P);
    res += solve(H, R, K - 1) * P;
  } else {
    res += solve(H, R, K - 1) * (1 - P);
    res += solve(L, H, K - 1) * P;
  }
  return res;
}

int main() {
  int K;
  double R, L;
  cin >> K >> R >> L >> P >> E >> T;
  printf("%.8f\\n", solve(L, R, K));
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

double k, l, r, p, e, t;
double rec(int k, double l, double r) {
  if (l >= t - e && r <= t + e)
    return 1.0;
  if (r < t - e || l > t + e)
    return 0.0;
  if (k == 0)
    return abs(t - (l + r) / 2) <= e ? 1.0 : 0.0;

  double m = (l + r) / 2, res = 0;
  if (m < t) {
    res += rec(k - 1, m, r) * (1 - p);
    res += rec(k - 1, l, m) * p;
  } else {
    res += rec(k - 1, l, m) * (1 - p);
    res += rec(k - 1, m, r) * p;
  }
  return res;
}
int main() {
  cin >> k >> l >> r;
  cin >> p >> e >> t;
  double ans = rec(k, l, r);
  printf("%.9f\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c)                                                             \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

double k, l, r, p, e, t;
double rec(int k, double l, double r) {
  if (l >= t - e && r <= t + e)
    return 1.0;
  if (k == 0)
    return abs(t - (l + r) / 2) < e ? 1.0 : 0.0;

  double m = (l + r) / 2, res = 0;
  if (m < t) {
    res += rec(k - 1, m, r) * (1 - p);
    res += rec(k - 1, l, m) * p;
  } else {
    res += rec(k - 1, l, m) * (1 - p);
    res += rec(k - 1, m, r) * p;
  }
  return res;
}
int main() {
  cin >> k >> l >> r;
  cin >> p >> e >> t;
  double ans = rec(k, l, r);
  printf("%.9f\\n", ans);
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

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

double amax, amin, pp = 0, p, t, k;

void ppsum(vector<bool> v) {
  double tmp = 1;
  for (int i = 0; i < v.size(); i++) {
    if (v[i])
      tmp *= (1 - p);
    else
      tmp *= p;
  }
  pp += tmp;
}

void night(double r, double l, vector<bool> v) {
  double h = (l + r) / 2;
  if (v.size() == k || v.size() > 23) {
    if (h >= amin && h <= amax) {
      ppsum(v);
    }
    return;
  }
  if (l < amin || r > amax)
    return;
  else {
    v.push_back(true);
    (h >= t) ? night(r, h, v) : night(h, l, v);
    v[v.size() - 1] = false;
    (h >= t) ? night(h, l, v) : night(r, h, v);
  }
}

void solve(int _k, int r, int l, double _p, double e, double _t) {
  p = _p;
  k = _k;
  t = _t;
  amin = t - e;
  amax = t + e;
  vector<bool> v;
  night((double)r, (double)l, v);
  printf("%.13lf", pp);
}

int main() {
  int a, b, c;
  double d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  solve(a, b, c, d, e, f);
}

Error: TLE

Fixed submission:

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

double amax, amin, pp = 0, p, t, k;

void ppsum(vector<bool> v) {
  double tmp = 1;
  for (int i = 0; i < v.size(); i++) {
    if (v[i])
      tmp *= (1 - p);
    else
      tmp *= p;
  }
  pp += tmp;
}

void night(double r, double l, vector<bool> v) {
  double h = (l + r) / 2;
  if (v.size() == k) {
    if (h >= amin && h <= amax) {
      ppsum(v);
    }
    return;
  }
  if (l < amin || r > amax)
    return;
  else {
    v.push_back(true);
    (h >= t) ? night(r, h, v) : night(h, l, v);
    v[v.size() - 1] = false;
    (h >= t) ? night(h, l, v) : night(r, h, v);
  }
}

void solve(int _k, int r, int l, double _p, double e, double _t) {
  p = _p;
  k = _k;
  t = _t;
  amin = t - e;
  amax = t + e;
  vector<bool> v;
  night((double)r, (double)l, v);
  cout << pp << endl;
}

int main() {
  int a, b, c;
  double d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  solve(a, b, c, d, e, f);
}
Problem p01418 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int K, L, R;
double P, E, T;

double PP(int K, double L, double R) {
  double mid = (L + R) / 2.0;
  if (K == 0) {
    return (fabs(T - mid) < E ? 1.0 : 0.0);
  } else if (T - R > E || L - T > E) {
    return (0.0);
  } else if (T - L <= E && R - T <= E) {
    return (1.0);
  } else if (mid <= T) {
    return (P * PP(K - 1, L, mid) + (1.0 - P) * PP(K - 1, mid, R));
  } else {
    return ((1.0 - P) * PP(K - 1, L, mid) + P * PP(K - 1, mid, R));
  }
}

int main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << fixed << setprecision(10) << PP(K, L, R) << endl;
}

Error: MLE

Fixed submission:

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

int K, L, R;
double P, E, T;
map<pair<int, pair<double, double>>, double> dp;
double PP(int K, double L, double R) {
  double mid = (L + R) / 2.0;
  if (dp.find({K, {L, R}}) != dp.end()) {
    return (dp[{K, {L, R}}]);
  } else if (K == 0) {
    return (fabs(T - mid) < E ? 1.0 : 0.0);
  } else if (mid <= T) {
    return (dp[{K, {L, R}}] =
                P * PP(K - 1, L, mid) + (1.0 - P) * PP(K - 1, mid, R));
  } else {
    return (dp[{K, {L, R}}] =
                (1.0 - P) * PP(K - 1, L, mid) + P * PP(K - 1, mid, R));
  }
}

int main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << fixed << setprecision(10) << PP(K, L, R) << endl;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define EPS (1e-15)
using namespace std;

int K, R, L;
double P, E, T, ans, cnt;

void func(int k, double l, double r, double p) {
  double h = (l + r) / 2;
  cnt++;
  if (l - (T + E) > EPS || T - E - r > EPS)
    return;
  else if (l - (T - E) >= EPS && T + E - r >= EPS) {
    ans += p;
    return;
  }
  if (k == K && E - abs(h - T) >= EPS) {
    ans += p;
    return;
  }
  if (k == K)
    return;
  if (T <= h) {
    func(k + 1, l, h, p * (1 - P));
    func(k + 1, h, r, p * P);
  } else {
    func(k + 1, l, h, p * P);
    func(k + 1, h, r, p * (1 - P));
  }
}

int main() {
  cin >> K >> R >> L >> P >> E >> T;
  func(0, R, L, 1);
  // cout<<cnt<<endl;
  printf("%.15f\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

int K, R, L;
double P, E, T, ans, cnt;

void func(int k, double l, double r, double p) {
  double h = (l + r) / 2;
  //  if(r<T-E||T+E<l)return;
  if (k == K) {
    if (fabs(T - h) <= E)
      ans += p;
    return;
  }
  if (T <= h) {
    func(k + 1, l, h, p * (1 - P));
    func(k + 1, h, r, p * P);
  } else {
    func(k + 1, l, h, p * P);
    func(k + 1, h, r, p * (1 - P));
  }
}

int main() {
  cin >> K >> R >> L >> P >> E >> T;
  func(0, R, L, 1);
  cout << ans << endl;
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

double p, e, t;

double dfs(int k, double r, double l) {
  double h = (r + l) / 2;

  if (k == 0) {
    if (abs(t - h) < e)
      return 1;
    else
      return 0;
  }

  if (t - e <= l && r <= t + e)
    return 1;
  else if (r < t - e || t + e < l)
    return 0;

  if (h >= t) {
    return p * dfs(k - 1, r, h) + (1 - p) * dfs(k - 1, h, l);
  } else {
    return p * dfs(k - 1, h, l) + (1 - p) * dfs(k - 1, r, h);
  }
}

int main() {
  int k;
  double r, l;
  cin >> k >> l >> r >> p >> e >> t;
  cout << fixed << setprecision(10) << dfs(k, r, l) << endl;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

int k;
double r, l, p, e, t;

struct Data {
  double r, l;
  double p;
  int k;
};

map<pair<pair<double, double>, int>, double> m;

void bfs() {
  queue<Data> q;
  q.push(Data{r, l, 1, 0});

  while (not q.empty()) {
    Data u = q.front();
    q.pop();
    pair<double, double> pdd = make_pair(u.r, u.l);
    // cout << pdd.first << ' ' << pdd.second << endl;

    if (m.count(make_pair(pdd, u.k))) {
      m[make_pair(pdd, u.k)] += u.p;
      continue;
    }
    m[make_pair(pdd, u.k)] += u.p;
    if (u.k == k)
      continue;

    double h = (u.r + u.l) / 2;
    double a = h < t ? (1.0 - p) : p;

    q.push(Data{h, u.l, u.p * a, u.k + 1});
    q.push(Data{u.r, h, u.p * (1.0 - a), u.k + 1});
  }
}

int main() {
  cin >> k >> r >> l >> p >> e >> t;

  double right = r, left = l;
  rep(i, k) {
    double mid = (right + left) / 2;
    if (mid < t)
      right = mid;
    else
      left = mid;
  }

  bfs();

  double P = 0;
  for (auto it : m) {

    if (it.first.second != k)
      continue;
    // cout << it.second<<' ' << it.first.first.first << ' ' <<
    // it.first.first.second << endl;

    double mid = (it.first.first.first + it.first.first.second) / 2;
    if (abs(mid - t) <= e)
      P += it.second;
  }
  cout << fixed << setprecision(6) << P << endl;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;

double p, e, t;

double solve(int k, double l, double r) {
  double c = (l + r) / 2.0;
  if (k == 0) {
    return (t - e <= c && c <= t + e) ? 1.0 : 0.0;
  }
  if (t - e <= r && l <= t + e)
    return 1.0;
  if (l < t - e || t + e < r)
    return 0.0;

  if (c >= t) {
    return (1.0 - p) * solve(k - 1, c, r) + p * solve(k - 1, l, c);
  } else {
    return (1.0 - p) * solve(k - 1, l, c) + p * solve(k - 1, c, r);
  }
}

int main() {
  int k, r, l;
  cin >> k >> r >> l;
  cin >> p >> e >> t;
  double res = solve(k, l, r);
  cout << fixed << setprecision(10) << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> pii;

double p, e, t;

double solve(int k, double l, double r) {
  double c = (l + r) / 2.0;
  if (k == 0) {
    return (t - e <= c && c <= t + e) ? 1.0 : 0.0;
  }
  if (c >= t) {
    return (1.0 - p) * solve(k - 1, c, r) + p * solve(k - 1, l, c);
  } else {
    return (1.0 - p) * solve(k - 1, l, c) + p * solve(k - 1, c, r);
  }
}

int main() {
  int k, r, l;
  cin >> k >> r >> l;
  cin >> p >> e >> t;
  double res = solve(k, l, r);
  cout << fixed << setprecision(10) << res << endl;
  return 0;
}