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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;

int day[33];

double low, high;
LL sum = 0;

double P, E, T;
double Tp;
int K;
double res;
void gao(int u, int ntp, int tp, double R, double L) {
  double H = (R + L) / 2;
  // printf("H=%lf\\n",H);

  if (R >= low && L <= high) {
    res += pow(1 - P, ntp) * pow(P, tp);
    return;
  }
  if (R > high || L < low)
    return;

  if (u == K) {
    Tp = H;
    if (low <= Tp && Tp <= high) {
      // printf("%d  %d\\n", K-tp,tp);
      res += pow(1 - P, ntp) * pow(P, tp);
    }
    return;
  }
  if (H >= T) {
    gao(u + 1, ntp + 1, tp, R, H);

    gao(u + 1, ntp, tp + 1, H, L);
  } else {
    gao(u + 1, ntp, tp + 1, R, H);

    gao(u + 1, ntp + 1, tp, H, L);
  }
}
double R, L;
int main() {

  while (~scanf("%d%lf%lf", &K, &R, &L)) {
    scanf("%lf%lf%lf", &P, &E, &T);

    low = max(0.0, T - E);
    high = T + E;
    res = 0;
    gao(0, 0, 0, R, L);

    printf("%lf\\n", res);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;

int day[33];

double low, high;
LL sum = 0;

double P, E, T;
double Tp;
int K;
double res;
void gao(int u, int ntp, int tp, double R, double L) {
  double H = (R + L) / 2;
  // printf("H=%lf\\n",H);

  if (R >= low && L <= high) {
    res += pow(1 - P, ntp) * pow(P, tp);
    return;
  }
  if (R > high || L < low)
    return;

  if (u == K) {
    Tp = H;
    if (low <= Tp && Tp <= high) {
      // printf("%d  %d\\n", K-tp,tp);
      res += pow(1 - P, ntp) * pow(P, tp);
    }
    return;
  }
  if (H >= T) {
    gao(u + 1, ntp + 1, tp, R, H);

    gao(u + 1, ntp, tp + 1, H, L);
  } else {
    gao(u + 1, ntp, tp + 1, R, H);

    gao(u + 1, ntp + 1, tp, H, L);
  }
}
double R, L;
int main() {

  while (scanf("%d%lf%lf", &K, &R, &L)) {
    scanf("%lf%lf%lf", &P, &E, &T);

    low = max(0.0, T - E);
    high = T + E;
    res = 0;
    gao(0, 0, 0, R, L);

    printf("%lf\\n", res);
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
double cnt;
double p, t;
int K;
double e;
double ll, rr;
double dfs(double l, double r, int k, double tl, double tr) {
  double mid = (l + r) / 2.00;
  if (l > tl - 1e-12 && r < tr + 1e-12)
    return 1.0;
  if (r < tl + 1e-12 || l > tr - 1e-12)
    return 0.0;
  if (k == K) {
    if (mid < tr + 1e-12 && mid > tl - 1e-12)
      return 1.0;
    else
      return 0.0;
  }
  double pp;
  if (mid >= t - 1e-12)
    pp = 1.00 - p;
  else
    pp = p;
  return pp * dfs(l, mid, k + 1, tl, tr) +
         (1 - pp) * dfs(mid, r, k + 1, tl, tr);
}
int main() {
  // freopen("aaa.txt","r",stdin);
  // freopen("bbb.txt","w",stdout);
  while (cin >> K >> ll >> rr) {
    cin >> p >> e >> t;
    double kk = dfs(ll, rr, 0, t - e, t + e);
    printf("%.12lf\\n", kk);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const double EPS = 1e-12;
double P, T;
double Sov(int Rest, double L, double R, double tL, double tR) {
  double mid = (L + R) / 2;
  //  if (L>tL+EPS && R<tR-EPS)
  //     return 1;
  //  if (R<tL+EPS || L>tR-EPS)
  //      return 0;
  if (Rest == 0) {
    if (mid < tR - EPS && mid > tL + EPS)
      return 1;
    else
      return 0;
  }
  if (mid < T - EPS) {
    return (1 - P) * Sov(Rest - 1, mid, R, tL, tR) +
           P * Sov(Rest - 1, L, mid, tL, tR);
  } else {
    return P * Sov(Rest - 1, mid, R, tL, tR) +
           (1 - P) * Sov(Rest - 1, L, mid, tL, tR);
  }
}
int main() {
  int K;
  double L, R, E;
  while (~scanf("%d%lf%lf", &K, &L, &R)) {
    scanf("%lf%lf%lf", &P, &E, &T);
    printf("%.10lf\\n", Sov(K, L, R, T - E, T + E));
  }
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int R, L, K;
double P, E, T, ans = 0;

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

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

  b_search(0, R, L, 1);
  printf("%.8f\\n", ans);

  return 0;
}

Error: TLE

Fixed submission:

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

int R, L, K;
double P, E, T, ans = 0;

void b_search(int k, double r, double l, double p) {
  if (l <= (T - E) || (T + E) <= r)
    return;

  if (k == K) {
    double H = (r + l) / 2;
    if (T - E < H && H < T + E)
      ans += p;
  } else {
    double H = (r + l) / 2;
    if (H <= T) {
      b_search(k + 1, H, l, (1 - P) * p);
      b_search(k + 1, r, H, P * p);
    }
    if (H > T) {
      b_search(k + 1, r, H, (1 - P) * p);
      b_search(k + 1, H, l, P * p);
    }
  }
}

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

  b_search(0, R, L, 1);
  printf("%.8f\\n", ans);

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
typedef long long ll;
using namespace std;

int n;
double L, R, P, E, T;
double ans = 0;
void dfs(int now, double l, double r, double p, double e, double t) {

  if (l > (T + E) && (r > (T + E)))
    return;
  if (l < (T - E) && r < (T - E))
    return;
  if (l <= (T + E) && l >= (T - E) && r <= (T + E) && r >= (T - E)) {
    ans += p;
    return;
  }
  double h = (l + r) / 2.0;
  if (now == n) {
    if (fabs(h - T) <= E)
      ans += p;
    return;
  }
  if (h - T >= -1e-10) {
    dfs(now + 1, h, r, p * (P), e, t);
    dfs(now + 1, l, h, p * (1 - P), e, t);
  } else {
    dfs(now + 1, l, h, p * (P), e, t);
    dfs(now + 1, h, r, p * (1 - P), e, t);
  }
}
int main() {
  scanf("%d", &n);
  scanf("%lf%lf%lf%lf%lf", &L, &R, &P, &E, &T);
  dfs(0, L, R, 1, E, T);
  printf("%.10lf\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define lc (k << 1)
#define rc ((k << 1) | 1)
#define mi ((l + r) >> 1)
#define fk puts("fuck!")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int K;
const ld eps = 1e-10;
ld L, R, ans, pp, T, E;

void cal(int k, ld l, ld r, ld p) {
  // printf("k=%d K=%d l=%Lf r=%Lf p=%Lf\\n",k,K,l,r,p);
  if (k == K) {
    ld res = (l + r) / 2.0;
    if (fabs(res - T) < E + eps)
      ans += p;
    return;
  }
  if (L < l && r < R) {
    ans += p;
    return;
  }
  ld mid = (l + r) / 2.0;
  if (T <= mid) {
    cal(k + 1, l, mid, p * (1.0 - pp));
    cal(k + 1, mid, r, p * pp);
  } else {
    cal(k + 1, l, mid, p * pp);
    cal(k + 1, mid, r, p * (1.0 - pp));
  }
}

int main() {
  int l, r;
  scanf("%d%d%d", &K, &l, &r);
  double p, e, t;
  scanf("%lf%lf%lf", &p, &e, &t);
  ans = 0;
  pp = p;
  T = t;
  E = e;
  L = t - e, R = t + e;
  // printf("T=%Lf L=%Lf R=%Lf\\n",T,L,R);///
  cal(0, l, r, 1);

  double out = ans;
  printf("%.10f\\n", out);
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

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

double rec(int num, double r, double l) {
  if (t < r - e || l + e < t)
    return 0;
  if (t - e < r && l < t + e)
    return 1;
  double tt = (r + l) / 2;
  if (num == k) {
    if (abs(t - tt) < e)
      return 1;
    else
      return 0;
  }
  if (tt < t) {
    return p * rec(num + 1, r, tt) + (1.0 - p) * rec(num + 1, tt, l);
  } else {
    return (1.0 - p) * rec(num + 1, r, tt) + p * rec(num + 1, tt, l);
  }
}

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

  printf("%.12f\\n", rec(0, r, l));
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

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

double rec(int num, double r, double l) {
  if (t < r - e || l + e < t)
    return 0;
  double tt = (r + l) / 2;
  if (num == k) {
    if (abs(t - tt) < e)
      return 1;
    else
      return 0;
  }
  if (tt < t) {
    return p * rec(num + 1, r, tt) + (1.0 - p) * rec(num + 1, tt, l);
  } else {
    return (1.0 - p) * rec(num + 1, r, tt) + p * rec(num + 1, tt, l);
  }
}

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

  printf("%.12f\\n", rec(0, r, l));
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

int K;
long double P;
long double rec(const int n, const long double l, const long double r,
                const long double tl, const long double tr,
                const long double t) {
  const long double mid = (l + r) / 2;
  if (n == K) {
    return (tl <= mid and mid <= tr) ? 1 : 0;
  }
  if (tl <= l and r <= tr) {
    return 1;
  } else if (tr < l) {
    return 0;
  } else if (tl > r) {
    return 0;
  }
  if (tr <= mid) {
    return (1 - P) * rec(n + 1, l, mid, tl, tr, t);
  } else if (mid <= tl) {
    return (1 - P) * rec(n + 1, mid, r, tl, tr, t);
  } else {
    return ((t <= mid) ? 1 - P : P) * rec(n + 1, l, mid, tl, mid, t) +
           ((t > mid) ? 1 - P : P) * rec(n + 1, mid, r, mid, tr, t);
  }
}

int main() {
  cin >> K;
  long double R, L, E, T;
  cin >> R >> L >> P >> E >> T;
  const long double TL = T - E;
  const long double TR = T + E;
  cout << fixed << setprecision(15) << rec(0, R, L, TL, TR, T) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

int K;
long double P;
long double rec(const int n, const long double l, const long double r,
                const long double tl, const long double tr,
                const long double t) {
  const long double mid = (l + r) / 2;
  if (n == K) {
    return (tl <= mid and mid <= tr) ? 1 : 0;
  }
  if (tr <= mid) {
    return (1 - P) * rec(n + 1, l, mid, tl, tr, t);
  } else if (mid <= tl) {
    return (1 - P) * rec(n + 1, mid, r, tl, tr, t);
  } else {
    return ((t <= mid) ? 1 - P : P) * rec(n + 1, l, mid, tl, mid, t) +
           ((t > mid) ? 1 - P : P) * rec(n + 1, mid, r, mid, tr, t);
  }
}

int main() {
  cin >> K;
  long double R, L, E, T;
  cin >> R >> L >> P >> E >> T;
  const long double TL = T - E;
  const long double TR = T + E;
  cout << fixed << setprecision(15) << rec(0, R, L, TL, TR, T) << endl;

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

#include <cstring>
#include <stdio.h>

double P, E, T;

double fabs(double x) {
  if (x < 0)
    x = -x;
  return x;
}

double dfs(int k, double pro, double L, double R) {
  if (k == 0) {
    double mid = (L + R) / 2;
    if (fabs(mid - T) <= E)
      return pro;
    return 0;
  }
  if (T + E < L || T - E > R)
    return 0;
  double ans = 0;
  double mid = (L + R) / 2;
  if (fabs(R - T) <= E && fabs(T - L) <= E)
    return pro;
  if (mid >= T) {
    ans += dfs(k - 1, pro * (1 - P), L, mid);
    ans += dfs(k - 1, pro * P, mid, R);
  } else {
    ans += dfs(k - 1, pro * P, L, mid);
    ans += dfs(k - 1, pro * (1 - P), mid, R);
  }
  return ans;
}
int main() {
  // freopen("input.txt", "r", stdin);
  int K;
  double L, R;
  scanf("%d %lf %lf", &K, &L, &R);
  scanf("%lf %lf %lf", &P, &E, &T);
  double ans = dfs(K, 1.0, L, R);
  printf("%lf\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb(a) push_back(a)
#define INF 0x1f1f1f1f
#define lson idx << 1, l, mid
#define rson idx << 1 | 1, mid + 1, r
#define PI 3.1415926535898
void debug() {
#ifdef ONLINE_JUDGE
#else
  freopen("d:\\\\in.txt", "r", stdin);
  freopen("d:\\\\out1.txt", "w", stdout);
#endif
}
char getch() {
  char ch;
  while ((ch = getchar()) != EOF) {
    if (ch != ' ' && ch != '\\n')
      return ch;
  }
  return EOF;
}
int k;
double p, e, t;
double dfs(double l, double r, int n) {
  double m = (l + r) / 2;
  if (n == k) {
    return fabs(m - t) <= e ? 1 : 0;
  }
  double v = 0;
  if (m >= t - e && l <= t + e)
    v += (m <= t ? p : 1 - p) * dfs(l, m, n + 1);
  if (m <= t + e && r >= t - e)
    v += (m > t ? p : 1 - p) * dfs(m, r, n + 1);
  return v;
}
int main() {
  scanf("%d", &k);

  double l, r;
  scanf("%lf%lf%lf%lf%lf", &l, &r, &p, &e, &t);
  double x = dfs(l, r, 0);
  printf("%.12lf\\n", x);

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

#include <cmath>
#include <iostream>

using namespace std;

double P, E, T;

int C(int n, int r) {
  int res = 1;
  for (int i = 1; i <= r; ++i)
    res = res * (n - i + 1) / i;
  return res;
}

double Dfs(double L, double R, int cnt) {
  if (cnt == 0) {
    if (abs((R + L) * 0.5 - T) <= E)
      return 1.0;
    else
      return 0.0;
  } else if (T < R - E || L + E < T)
    return 0.0;
  else if (max(abs(R - T), abs(L - T)) <= E) {
    double res = 0.0;
    for (int i = 0; i <= cnt; ++i)
      res += C(cnt, i) * pow(1.0 - P, i) * pow(P, cnt - i);
    return res;
  }

  double H = (R + L) * 0.5;
  double res = 0.0;

  if (T > H) {
    res += (1.0 - P) * Dfs(L, H, cnt - 1);
    res += P * Dfs(H, R, cnt - 1);
  } else {
    res += (1.0 - P) * Dfs(H, R, cnt - 1);
    res += P * Dfs(L, H, cnt - 1);
  }

  return res;
}

int main() {
  int K;
  double R, L;

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

  printf("%.8f\\n", Dfs(L, R, K));

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

double P, E, T;

double Dfs(double L, double R, int cnt) {
  if (T < R - E || L + E < T)
    return 0.0;

  double H = (R + L) * 0.5;

  if (cnt == 0) {
    if (abs(H - T) <= E)
      return 1.0;
    else
      return 0.0;
  }

  double res = 0.0;
  if (T > H) {
    res += (1.0 - P) * Dfs(L, H, cnt - 1);
    res += P * Dfs(H, R, cnt - 1);
  } else {
    res += (1.0 - P) * Dfs(H, R, cnt - 1);
    res += P * Dfs(L, H, cnt - 1);
  }

  return res;
}

int main() {
  int K;
  double R, L;

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

  printf("%.8f\\n", Dfs(L, R, K));

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

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

#define EPS (1e-5)

double P, E, T;
double TR, TL;

double solve(int K, double R, double L) {
  double M = (R + L) / 2;

  if (K == 0)
    return (TR < M && M < TL ? 1 : 0);
  if (TR < R && L < TL)
    return 1;
  if (L < TR || TL < R)
    return 0;

  double res = 0;

  if (M - T > -EPS) {
    res += (1 - P) * solve(K - 1, R, M);
    res += P * solve(K - 1, M, L);
  } else {
    res += (1 - P) * solve(K - 1, M, L);
    res += P * solve(K - 1, R, M);
  }

  return res;
}

int main() {
  int K;
  double R, L;

  while (cin >> K >> R >> L >> P >> E >> T) {
    TR = T - E;
    TL = T + E;
    printf("%.10f\\n", solve(K, R, L));
  }
}

Error: 0

Fixed submission:

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

#define EPS (1e-15)

double P, E, T;

double solve(int K, double R, double L) {
  if (K == 0) {
    double M = (R + L) / 2;
    if (fabs(T - M) < E + EPS) {
      return 0;
    }
    return 1;
  }

  double M = (R + L) / 2;
  double res = 0;

  if (M - T > -EPS) { // Lツづーツ陛渉更ツつキツづゥツづ個つェツ青ウツ嘉ー
    if (M - T < E + EPS) {
      res = (1 - P) * solve(K - 1, M, L);
    } else {
      res = P * solve(K - 1, R, M);
      res += 1 - P;
    }
  } else { // Rツづーツ陛渉更ツつキツづゥツづづヲツつ「
    if (T - M < E + EPS) {
      res = (1 - P) * solve(K - 1, R, M);
    } else {
      res = P * solve(K - 1, M, L);
      res += 1 - P;
    }
  }

  return res;
}

int main() {
  int K;
  double R, L;

  while (cin >> K >> R >> L) {
    cin >> P >> E >> T;
    P = 1.0 - P;

    double M = (R + L) / 2;
    double a = solve(K - 1, M, L);
    double b = solve(K - 1, R, M);
    double ans;

    if (M - T > -EPS)
      ans = 1.0 - P * b - (1.0 - P) * a;
    else
      ans = 1.0 - P * a - (1.0 - P) * b;

    printf("%.6f\\n", ans);
  }
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define PI 3.1415926535897932384626433832795028
#define N 30
#define M 10010
#define inf 2000000000
typedef long long LL;
int k;
double p, e, t, ans;
void dfs(int cur, double l, double r, double temp) {
  if (l > t + e || r < t - e)
    return;
  if (l >= t - e && r <= t + e) {
    ans += temp;
    return;
  }
  double mid = (l + r) / 2;
  if (cur == k) {
    if (fabs(mid - t) < e)
      ans += temp;
    return;
  }
  if (mid > t) {
    dfs(cur + 1, l, mid, temp * (1 - p));
    dfs(cur + 1, mid, r, temp * p);
  } else {
    dfs(cur + 1, mid, r, temp * (1 - p));
    dfs(cur + 1, l, mid, temp * p);
  }
}
int main() {
  double l, r;
  while (scanf("%d%lf%lf", &k, &l, &r) != EOF) {
    scanf("%lf%lf%lf", &p, &e, &t);
    ans = 0;
    dfs(0, l, r, 1.0);
    printf("%.6lf\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define eps 0.0000000001

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

void dfs(double l, double r, int deep, double p) {
  double t = (l + r) / 2;
  if (deep == K) {
    // cout << "T,t,p " << T << " " << t << " " << p << endl;
    if (abs(t - T) - eps <= E) {
      // cout << p << endl;
      PP += p;
    }

    return;
  }

  if (t + eps >= T) {
    dfs(l, t, deep + 1, p * (1 - P));
    dfs(t, r, deep + 1, p * P);
  } else {
    dfs(l, t, deep + 1, p * P);
    dfs(t, r, deep + 1, p * (1 - P));
  }
}

int main(int argc, char *argv[]) {
  while (cin >> K >> L >> R >> P >> E >> T) {
    // cout << "E,T " << E << " " << T << endl;
    PP = 0;
    dfs(L, R, 0, 1);
    printf("%.11lf\\n", PP);
  }
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define INF 0x7fffffff
#define Max 200000
#define eps 1e-10

double l, r, p, e, t, ans;
int c;

void dfs(double L, double R, int days, double pp) {
  if (R < (t - e) || L > (t + e))
    return;
  if (L >= t - e && R <= t + e) {
    ans += pp;
    return;
  }
  double mid = (L + R) / 2.0;
  if (days > c) {
    if (abs(mid - t) <= e)
      ans += pp;
    return;
  }
  if (mid >= t) {
    dfs(L, mid, days + 1, pp * (1 - p));
    dfs(mid, R, days + 1, pp * p);
  } else {
    dfs(mid, R, days + 1, pp * (1 - p));
    dfs(L, mid, days + 1, pp * p);
  }
}

int main() {
  int i, j;
  while (scanf("%d%lf%lf", &c, &l, &r) == 3) {
    scanf("%lf%lf%lf", &p, &e, &t);
    ans = 0;
    dfs(l, r, 1, 1);
    printf("%.20lf\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>

int k;
double r, l, p, e, t, ans = 0;

void dfs(int rank, double pp, double r, double l) {
  if (r - t > e || t - l > e)
    return;
  double h = (r + l) / 2.0;
  if (rank == k) {
    if (fabs(h - t) <= e) {
      ans += pp;
    }
    return;
  }
  if (h >= t) {
    dfs(rank + 1, pp * (1 - p), r, h);
    dfs(rank + 1, pp * p, h, l);
  } else {
    dfs(rank + 1, pp * p, r, h);
    dfs(rank + 1, pp * (1 - p), h, l);
  }
}

int main() {
  scanf("%d%lf%lf%lf%lf%lf", &k, &r, &l, &p, &e, &t);
  dfs(0, 1.0, r, l);
  printf("%lf\\n", ans);
  return 0;
}