Problem:
Sleeping Time
Miki is a high school student.
She has  a part time job, so she cannot take enough sleep  on weekdays.
She wants to take good sleep  on holidays, but she doesn't know  the  best length of sleeping time for her.

She is now trying to figure that out with the following algorithm:
Begin with the numbers
K
,
R
and
L
.
She  tries to sleep for
H=(R+L)/2
hours.
If she feels  the time is longer than or equal to the optimal length, then  update
L
with
H
.  Otherwise,  update
R
with
H
.
After repeating step 2 and  3 for
K
nights, she decides her optimal sleeping time to be
T' = (R+L)/2
.
If her feeling  is always correct,  the steps described above should give her a very accurate optimal sleeping time.
But unfortunately, she makes mistake in step 3  with the probability
P
.
Assume you know  the optimal sleeping time
T
for Miki.
You have to calculate the probability
PP
that the absolute difference of
T'
and
T
is  smaller or equal to
E
.
It is guaranteed that the answer remains unaffected  by the change of
E
in
10^{-10}
.
Input
The input follows the format shown below
K
R
L
P
E
T
Where the integers
0 \leq K \leq 30
,
0 \leq R \leq L \leq 12
are the parameters for the algorithm described above.
 The decimal numbers on the following three lines of the input gives the parameters for the estimation.  You can assume
0 \leq P \leq 1
,
0 \leq E \leq 12
,
0 \leq T \leq 12
.
Output
Output
PP
in one line.

The output should not contain an error greater than
10^{-5}
.
Sample Input 1
3 0 2
0.10000000000
0.50000000000
1.00000000000
Output for the Sample Input 1
0.900000
Sample Input 2
3 0 2
0.10000000000
0.37499999977
1.00000000000
Output for the Sample Input 2
0.810000
Sample Input 3
3 0 2
0.10000000000
0.00000100000
0.37500000000
Output for the Sample Input 3
0.729000
Sample Input 4
3 0 2
0.20000000000
0.00000100000
0.37500000000
Output for the Sample Input 4
0.512000

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
template <class T>
inline bool rd(T &ret) {
    char c; int sgn;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    ret*=sgn;
    return 1;
}
template <class T>
inline void pt(T x) {
    if (x <0) {
        putchar('-');
        x = -x;
    }
    if(x>9) pt(x/10);
    putchar(x%10+'0');
}
using namespace std;
const double eps = 1e-7;
int K;
double L, R, P, E, T;
double ans ;
void dfs(double l, double r, double p, int dep){
    if(fabs(T-l) <= E && fabs(T-r) <= E) {ans += p; return ;}
    double mid = (l+r)/2.0;
    if(dep >= K)
    {
        if(fabs(T-mid) <= E) ans += p;
        return ;
    }
    if(p < eps) return ;
    if(mid < T)
    {
        dfs(mid, r, p*(1.0-P), dep+1);
        dfs(l, mid, p*P, dep+1);
    }
    else
    {
        dfs(mid, r, p*P, dep+1);
        dfs(l, mid, p*(1.0-P), dep+1);
    }
}
int main(){
    while(~scanf("%d %lf %lf", &K, &L, &R)){
        scanf("%lf %lf %lf", &P, &E, &T);
        ans = 0;
        dfs(L, R, 1.0, 0);
        printf("%.10f\n", ans);
    }
    return 0;
}
/*
30 0 12
0.5
0
13

*/
accuracy: 1
time_ms: 60
memory_kb: 3564
final_rank: 1

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

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

double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;

  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;

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

  double left_dfs = dfs(d - 1, l, mid);
  double right_dfs = dfs(d - 1, mid, r);

  if (mid >= T)
    return (1.0 - P) * left_dfs + P * right_dfs;

  return (1.0 - P) * right_dfs + P * left_dfs;
}

int main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));

  return 0;
}
accuracy: 1
time_ms: 3300
memory_kb: 3284
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;

double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d) {
    return ((mid > T - E) && (mid < T + E)) ? 1.0 : 0.0;
  }
  if (r < T - E || l > T + E) {
    return 0.0;
  }
  
  double res = dfs(d - 1, mid, r); // store result of dfs() call in a variable
  if (mid >= T) {
    return (1.0 - P) * dfs(d - 1, l, mid) + P * res; 
  }
  return (1.0 - P) * res + P * dfs(d - 1, l, mid);
}

int main() {
  scanf("%d %d %d %lf %lf %lf", &K, &L, &R, &P, &E, &T);
  printf("%.9f\n", dfs(K, L, R));
  return 0;
}
accuracy: 1
time_ms: 3260
memory_kb: 3248
final_rank: 2

code_snippet: #include <iostream>
#include <cstdio>

double dfs(int d, double l, double r, double T, double E, double P) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid, T, E, P) + P * dfs(d - 1, mid, r, T, E, P);
  return (1.0 - P) * dfs(d - 1, mid, r, T, E, P) + P * dfs(d - 1, l, mid, T, E, P);
}

int main() {
  int K, L, R;
  double P, E, T;
  std::cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R, T, E, P));
  return 0;
}
accuracy: 1
time_ms: 3610
memory_kb: 3284
final_rank: 13

code_snippet: #include <iostream>
#include <cmath>

int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cin >> K >> L >> R >> P >> E >> T;
  std::cout.precision(9);
  std::cout << dfs(K, L, R) << "\n";
  return 0;
}
accuracy: 0.28378378378378377
time_ms: 3220
memory_kb: 3292
final_rank: 18

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

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

double dfs(int d, double l, double r) {
  double mid = (l + r) * .5;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1. : .0;
  if (r < T - E || T + E < l)
    return .0;
  if (mid >= T)
    return (1. - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1. - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}

int main() {
  std::ios::sync_with_stdio(false); // faster I/O
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs((int)K, L, R));
  return 0;
}
accuracy: 1
time_ms: 3210
memory_kb: 3292
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  if (r < T - E || T + E < l)
    return 0;
  double mid = (l + r) * 0.5;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
int main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
  return 0;
}
accuracy: 1
time_ms: 3400
memory_kb: 3272
final_rank: 9

code_snippet: #include <iostream>
#include <cmath>

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

double dfs(int d, double l, double r) {
    double mid = l + ((r - l) / 2);
    if (d == 0)
        return (std::abs(mid - T) <= E) ? 1 : 0;
    if (r < T - E || T + E < l)
        return 0;
    double p1 = P * dfs(d - 1, l, mid);
    double p2 = (1.0 - P) * dfs(d - 1, mid, r);
    if (mid >= T)
        return p2 + p1;
    return p1 + p2;
}

int main() {
    std::cin >> K >> L >> R >> P >> E >> T;
    std::cout.precision(9);
    std::cout << dfs(K, L, R) << std::endl;
    return 0;
}
accuracy: 0.13513513513513514
time_ms: 30
memory_kb: 3272
final_rank: 20

code_snippet: #include <iostream>
#include <cstdio>

double P, E, T;
int K;
double dfs(int d, double l, double r) {
    if (r < T - E || T + E < l)
        return 0;
    if (!d)
        return 1;
    double mid = l + (r - l) / 2;
    if (mid >= T)
        return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
    return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}

int main() {
    double L, R;
    std::cin >> K >> L >> R >> P >> E >> T;
    printf("%.9f\n", dfs(K, L, R));
    return 0;
}
accuracy: 0.5135135135135135
time_ms: 3410
memory_kb: 3272
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K;
double P, E, T;
double dfs(int d, double l, double r) {
    double mid = (l + r) * 0.5;
    if (d == 0)
        return (fabs(mid - T) <= E) ? 1.0 : 0.0;
    if (r < T - E || T + E < l)
        return 0.0;
    if (mid >= T)
        return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
    return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
int main() {
    double L, R;
    cin >> K >> L >> R >> P >> E >> T;
    cout << fixed << setprecision(9) << dfs(K, L, R) << "\n";
    return 0;
}
accuracy: 1
time_ms: 3270
memory_kb: 3272
final_rank: 7

code_snippet: #include <iostream>
#include <cstdio>

using namespace std;

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

double dfs(int d, double l, double r) {
  if (r < T - E || T + E < l) return 0;
  if (!d) return (T - E < r && l < T + E) ? 1 : 0;
  double mid = l + (r - l) / 2;
  if (mid >= T) return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  else return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}

int main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
  return 0;
}
accuracy: 0.5135135135135135
time_ms: 3240
memory_kb: 3272
final_rank: 14

code_snippet: #include <iostream>
#include <cstdio>

double P, E, T;
int K;
double dfs(int d, double l, double r) {
  double mid = l + (r - l) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
int main() {
  int L, R;
  std::cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
  return 0;
}
accuracy: 1
time_ms: 3440
memory_kb: 3272
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
}
accuracy: 1
time_ms: 3260
memory_kb: 3272
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << dfs(K, L, R);
}
accuracy: 0.28378378378378377
time_ms: 3290
memory_kb: 3272
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
int main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
}
accuracy: 1
time_ms: 3260
memory_kb: 3272
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.10f\n", dfs(K, L, R));
}
accuracy: 1
time_ms: 3250
memory_kb: 3272
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (mid < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
}
accuracy: 0.13513513513513514
time_ms: 10
memory_kb: 3172
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  cout << dfs(K, L, R) << endl;
}
accuracy: 0.28378378378378377
time_ms: 3190
memory_kb: 3272
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T)
    return (1.0 - P) * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  return (1.0 - P) * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
main() {
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9lf\n", dfs(K, L, R));
}
accuracy: 1
time_ms: 3250
memory_kb: 3272
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int K, R, L;
double P, E, T;
double dfs(int d, double l, double r) {
  double mid = (l + r) / 2;
  if (!d)
    return (T - E < mid && mid < T + E) ? 1 : 0;
  if (r < T - E || T + E < l)
    return 0;
  if (mid >= T) {
    double p = 1.0 - P;
    return p * dfs(d - 1, l, mid) + P * dfs(d - 1, mid, r);
  }
  double p = 1.0 - P;
  return p * dfs(d - 1, mid, r) + P * dfs(d - 1, l, mid);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> K >> L >> R >> P >> E >> T;
  printf("%.9f\n", dfs(K, L, R));
  return 0;
}
accuracy: 1
time_ms: 3350
memory_kb: 3308
final_rank: 12