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

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)

const double EPS = 1.0e-10;
int K;
double UB, LB, P, E, T;
double dfs(double lb, double ub, int turn) {
  if (T + E + EPS < lb)
    return 0.0;
  if (ub < T - E - EPS)
    return 0.0;
  if (T - E + EPS < lb && ub < T + E - EPS)
    return 1.0;
  double mid = (lb + ub) / 2;
  if (turn == 0)
    return abs(T - mid) <= (EPS + E) ? 1.0 : 0.0;
  double res = 0.0;
  double p1 = 1.0 - P, p2 = P;
  if ((T - EPS) <= mid)
    swap(p1, p2);
  res += dfs(mid, ub, turn - 1) * p1;
  res += dfs(lb, mid, turn - 1) * p2;
  return res;
}
int main() {
  scanf("%d%lf%lf%lf%lf%lf", &K, &LB, &UB, &P, &E, &T);
  printf("%.10f\\n", dfs(LB, UB, K));
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)

const double EPS = 1.0e-10;
int K;
double UB, LB, P, E, T;
bool check(double a) { return abs(T - a) <= (EPS + E); }
double dfs(double lb, double ub, int turn) {
  double mid = (lb + ub) / 2;
  if (turn == 0)
    return check(mid) ? 1.0 : 0.0;
  double res = 0.0;
  double p1 = 1.0 - P, p2 = P;
  if ((T - EPS) <= mid)
    swap(p1, p2);
  res += dfs(mid, ub, turn - 1) * p1;
  res += dfs(lb, mid, turn - 1) * p2;
  return res;
}
int main() {
  scanf("%d%lf%lf%lf%lf%lf", &K, &LB, &UB, &P, &E, &T);
  printf("%.10f\\n", dfs(LB, UB, K));
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < n; i++)

static const double EPS = 1E-10;
template <typename T> T add(T x, T y) {
  if (abs(x + y) < EPS * (abs(x) + abs(y)))
    return 0;
  return x + y;
}
template <typename T> inline bool semieq(T x, T y) { return abs(x - y) < EPS; }
template <typename T> inline bool semige(T x, T y) { return y - x < -EPS; }
template <typename T> inline bool semile(T x, T y) { return x - y < -EPS; }

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

inline double solve(int k, double l, double r) {
  if (semige(r, T + E) || semile(l, T - E))
    return 0.0;
  if (!semile(r, T - E) && !semige(l, T + E))
    return 1.0;
  double h = (l + r) / 2.0;
  if (k >= K)
    return !semige(abs(h - T), E) ? 1.0 : 0.0;
  double ret = 0.0;
  if (h >= T) {
    ret += P * solve(k + 1, l, h);
    ret += (1.0 - P) * solve(k + 1, h, r);
  } else {
    ret += P * solve(k + 1, h, r);
    ret += (1.0 - P) * solve(k + 1, l, h);
  }
  return ret;
}

int main(int argc, char *argv[]) {
  cin >> K >> R >> L;
  cin >> P >> E >> T;

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < n; i++)

static const double EPS = 0.0;
template <typename T> T add(T x, T y) {
  if (abs(x + y) < EPS * (abs(x) + abs(y)))
    return 0;
  return x + y;
}
template <typename T> inline bool semieq(T x, T y) { return abs(x - y) < EPS; }
template <typename T> inline bool semige(T x, T y) { return y - x < -EPS; }
template <typename T> inline bool semile(T x, T y) { return x - y < -EPS; }

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

inline double solve(int k, double l, double r) {
  if (semige(r, T + E) || semile(l, T - E))
    return 0.0;
  double h = (l + r) / 2.0;
  if (k >= K)
    return !semige(abs(h - T), E) ? 1.0 : 0.0;
  double ret = 0.0;
  if (h >= T) {
    ret += P * solve(k + 1, l, h);
    ret += (1.0 - P) * solve(k + 1, h, r);
  } else {
    ret += P * solve(k + 1, h, r);
    ret += (1.0 - P) * solve(k + 1, l, h);
  }
  return ret;
}

int main(int argc, char *argv[]) {
  cin >> K >> R >> L;
  cin >> P >> E >> T;

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

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

#include <bits/stdc++.h>
using namespace std;
double P, E, T;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (k == 0 || (abs(L - T) <= E && abs(R - T) <= E))
    return abs(H - T) <= E;
  if (T < R - E || L + E < T)
    return 0;
  return PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
double P, E, T;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (k == 0 || (abs(L - T) <= E && abs(R - T) <= E))
    return abs(H - T) <= E;
  return PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

#include <cmath>
#include <cstdio>

double P, E, T;

double dfs(int K, double L, double R) {
  double H = 0.5 * (L + R);
  if (K == 0)
    return (std::abs(T - H) < E) ? 1.0 : 0.0;

  double LH = dfs(K - 1, L, H);
  double HR = dfs(K - 1, H, R);
  if (H >= T) {
    return P * HR + (1.0 - P) * LH;
  } else {
    return P * LH + (1.0 - P) * HR;
  }
}

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

  printf("%.12f\\n", dfs(K, L, R));
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>

double dfs(int K, double L, double R, double P, double E, double T) {
  double H = 0.5 * (L + R);
  if (K == 0)
    return (std::abs(T - H) < E);

  double LH = dfs(K - 1, L, H, P, E, T);
  double HR = dfs(K - 1, H, R, P, E, T);
  if (H >= T) {
    return P * HR + (1.0 - P) * LH;
  } else {
    return P * LH + (1.0 - P) * HR;
  }
}

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

  printf("%.12f\\n", dfs(K, L, R, P, E, T));
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
double p, e, t;
double fi(int k, double l, double r) {
  double c = (l + r) / 2;
  if (!k)
    return fabs(c - t) <= e;
  if (t - e < l && r < t + e)
    return 1;
  if (t - e > r || l > t + e)
    return 0;
  if (c < t)
    return fi(k - 1, c, r) * (1 - p) + fi(k - 1, l, c) * p;
  else
    return fi(k - 1, l, c) * (1 - p) + fi(k - 1, c, r) * p;
}
int main() {
  int k, l, r;
  scanf("%d%d%d", &k, &l, &r);
  // double p,e,t;
  scanf("%lf%lf%lf", &p, &e, &t);
  printf("%.6f\\n", fi(k, l, r));
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
double p, e, t;
double fi(int k, double l, double r) {
  if (!k)
    return fabs((l + r) / 2 - t) <= e;
  if (t < l - e || r + e < t)
    return 0;
  return fi(k - 1, (l + r) / 2 > t ? l : (l + r) / 2,
            (l + r) / 2 > t ? (l + r) / 2 : r) *
             (1 - p) +
         fi(k - 1, (l + r) / 2 > t ? (l + r) / 2 : l,
            (l + r) / 2 > t ? r : (l + r) / 2) *
             p;
}
int main() {
  int k, l, r;
  scanf("%d%d%d", &k, &l, &r);
  // double p,e,t;
  scanf("%lf%lf%lf", &p, &e, &t);
  printf("%.6f\\n", fi(k, l, r));
  return 0;
}
Problem p01418 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
double P, E, T;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (k == 0)
    return abs(H - T) <= E;
  if (abs(L - T) <= E && abs(R - T) <= E)
    return 1;
  if (T < R - E || L + E < T)
    return 0;

  return PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
double P, E, T;
typedef pair<double, double> p;
map<p, double> M;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (k == 0)
    return abs(H - T) <= E;
  if (M.count(p(L, R)))
    return M[p(L, R)];
  if (T < R - E || L + E < T)
    return 0;
  return M[p(L, R)] = PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

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

double R, L, H;
double P, E, T;
int k;

double sleep(double L, double R, double k) {
  double H = (L + R) / 2;
  if (!k) {
    if (abs(T - H) > E)
      return 0.0;
    return 1.0;
  }

  if (T - E < R && L < T + E)
    return 1.0;
  if (T + E < R)
    return 0.0;
  if (T - E > L)
    return 0.0;

  if (H < T)
    return P * sleep(H, R, k - 1) + (1.0 - P) * sleep(L, H, k - 1);
  else
    return (1.0 - P) * sleep(H, R, k - 1) + P * sleep(L, H, k - 1);
}

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

  printf("%.8lf\\n", sleep(L, R, k));
}

Error: TLE

Fixed submission:

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

double R, L, H;
double P, E, T;
int k;

double sleep(double L, double R, double k) {
  double H = (L + R) / 2;
  if (!k) {
    if (abs(T - H) > E)
      return 0.0;
    return 1.0;
  }

  if (T + E < R)
    return 0.0;
  if (T - E > L)
    return 0.0;

  if (H < T)
    return P * sleep(H, R, k - 1) + (1.0 - P) * sleep(L, H, k - 1);
  else
    return (1.0 - P) * sleep(H, R, k - 1) + P * sleep(L, H, k - 1);
}

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

  printf("%.8lf\\n", sleep(L, R, k));
}
Problem p01418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define EPS (1e-10)
using namespace std;
double P, E, T;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (k == 0)
    return abs(H - T) <= E;
  if (T < R - E || L + E < T)
    return 0;
  return PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
double T, E, P;

double dfs(int k, double L, double R) {
  double H = (R + L) / 2, PP = H >= T ? 1 - P : P;
  if (R - L > T)
    return 0;
  if (k == 0)
    return abs(H - T) <= E;
  return PP * dfs(k - 1, H, R) + (1 - PP) * dfs(k - 1, L, H);
}

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

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

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

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

  double h = (r + l) / 2;

  if (k == 0) {
    if (t - e <= h && h <= t + e) {
      return 1.0;
    } else
      return 0.0;
  }

  double k1 = 1.0 - p, k2 = p;
  if (t > h) {
    swap(k1, k2);
  }

  return k1 * solve(k - 1, r, h) + k2 * solve(k - 1, h, l);
}

int main() {
  cin >> k >> r >> l >> p >> e >> t;
  printf("%.20f\\n", solve(k, r, l));
}

Error: TLE

Fixed submission:

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

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

double solve(int k, double r, double l) {
  if (t + e < r || l < t - e) {
    return 0.0;
  }

  double h = (r + l) / 2;

  if (k == 0) {
    if (t - e <= h && h <= t + e) {
      return 1.0;
    } else
      return 0.0;
  }

  double k1 = 1.0 - p, k2 = p;
  if (t > h) {
    swap(k1, k2);
  }

  return k1 * solve(k - 1, r, h) + k2 * solve(k - 1, h, l);
}

int main() {
  cin >> k >> r >> l >> p >> e >> t;
  printf("%.20f\\n", solve(k, r, l));
}
Problem p01420 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
using namespace std;
int n, m, l, p[111], t[111], v[111];
long double r[111][55], dp[55][55];
int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    cin >> p[i] >> t[i] >> v[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++)
      fill(dp[j], dp[j] + m + 1, 0.0);
    dp[0][0] = 1;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k <= j; k++) {
        dp[j + 1][k] += dp[j][k] * (100 - p[i]) / 100;
        dp[j + 1][k + 1] += dp[j][k] * p[i] / 100;
      }
    }
    for (int j = 0; j <= m; j++)
      r[i][j] = dp[m][j];
  }
  for (int i = 0; i < n; i++) {
    long double ret = 0;
    if (v[i] != 0) {
      long double time1 = 1.0L * l / v[i];
      for (int j = 0; j <= m; j++, time1 += t[i]) {
        long double res = r[i][j];
        for (int k = 0; k < n; k++) {
          if (i == k)
            continue;
          long double sum = 0;
          if (v[k] != 0) {
            double time2 = 1.0 * l / v[k];
            for (int l = 0; l <= m; l++, time2 += t[k]) {
              if (time1 + 1e-10L < time2)
                sum += r[k][l];
            }
          } else
            sum = 1;
          res *= sum;
        }
        ret += res;
      }
    }
    cout << fixed << setprecision(15) << ret << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;
int n, m, l, p[111], t[111], v[111];
double r[111][55], dp[55][55];
int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    cin >> p[i] >> t[i] >> v[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++)
      fill(dp[j], dp[j] + m + 1, 0.0);
    dp[0][0] = 1;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k <= j; k++) {
        dp[j + 1][k] += dp[j][k] * (100 - p[i]) / 100;
        dp[j + 1][k + 1] += dp[j][k] * p[i] / 100;
      }
    }
    for (int j = 0; j <= m; j++)
      r[i][j] = dp[m][j];
  }
  for (int i = 0; i < n; i++) {
    double ret = 0, time1 = l / v[i];
    for (int j = 0; j <= m; j++, time1 += t[i]) {
      double res = r[i][j];
      for (int k = 0; k < n; k++) {
        if (i == k)
          continue;
        double sum = 0, time2 = l / v[k];
        for (int l = 0; l <= m; l++, time2 += t[k]) {
          if (time1 < time2)
            sum += r[k][l];
        }
        res *= sum;
      }
      ret += res;
    }
    cout << fixed << setprecision(15) << ret << endl;
  }
  return 0;
}
Problem p01420 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define T 6005
#define N 105
#define M 55
using namespace std;
int n, m, l, p[N], t[N], v[N];
double dp[N][2][T], sum[N][T];

int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    cin >> p[i] >> t[i] >> v[i];
  for (int i = 0; i < n; i++) {
    dp[i][0][0] = 1;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < T; k++) {
        if (!dp[i][j % 2][k])
          continue;
        dp[i][(j + 1) % 2][k] += dp[i][j % 2][k] * (100.0 - p[i]) / 100.0;
        dp[i][(j + 1) % 2][k + t[i]] += dp[i][j % 2][k] * p[i] / 100.0;
      }
      for (int k = 0; k < T; k++)
        dp[i][j % 2][k] = 0;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = T - 2; j >= 0; j--)
      sum[i][j] = sum[i][j + 1] + dp[i][m % 2][j];
  for (int i = 0; i < n; i++) {
    double ans = 0;
    if (v[i])
      for (int j = 0; j < T; j++) {
        if (!dp[i][m % 2][j])
          continue;
        double x = dp[i][m % 2][j];
        double s = j + 1.0 * l / v[i];
        for (int k = 0; k < n; k++) {
          if (i == k || !v[k])
            continue;
          int idx = (int)(s - 1.0 * l / v[k]);
          if (s - 1.0 * l / v[k] < 0)
            idx = 0;
          else
            idx++;
          if (T <= idx) {
            x = 0;
            break;
          }
          x *= sum[k][idx];
        }
        ans += x;
      }
    printf("%.8f\\n", ans);
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define T 100005
#define N 105
#define M 55
using namespace std;
int n, m, l, p[N], t[N], v[N];
double dp[N][2][T], sum[N][T];

int main() {
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    cin >> p[i] >> t[i] >> v[i];

  for (int i = 0; i < n; i++) {
    dp[i][0][0] = 1;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < T; k++) {
        if (!dp[i][j % 2][k])
          continue;
        dp[i][(j + 1) % 2][k] += dp[i][j % 2][k] * (100.0 - p[i]) / 100.0;
        dp[i][(j + 1) % 2][k + t[i]] += dp[i][j % 2][k] * p[i] / 100.0;
      }
      for (int k = 0; k < T; k++)
        dp[i][j % 2][k] = 0;
    }
  }

  for (int i = 0; i < n; i++)
    for (int j = T - 2; j >= 0; j--)
      sum[i][j] = sum[i][j + 1] + dp[i][m % 2][j];

  for (int i = 0; i < n; i++) {
    double ans = 0;
    if (v[i])
      for (int j = 0; j < T; j++) {
        if (!dp[i][m % 2][j])
          continue;
        double x = dp[i][m % 2][j];
        double s = j + 1.0 * l / v[i];

        for (int k = 0; k < n; k++) {
          if (i == k || !v[k])
            continue;
          int idx = max(0, (int)(s - 1.0 * l / v[k]) + 1);
          x *= sum[k][idx];
        }
        ans += x;
      }
    printf("%.8f\\n", ans);
  }
  return 0;
}
Problem p01420 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define INF 1e15
using namespace std;
typedef long long ll;

int N, M, L, P[100], T[100], V[100];
double p[100][51];

ll combination(ll n, ll r) {
  static ll comb[51][51];
  ll &ret = comb[n][r];
  if (ret != 0)
    return ret;
  if (n == 0 || r == 0)
    return ret = 1;
  if (n == r)
    return ret = 1;
  if (r == 1)
    return ret = n;
  return ret = combination(n - 1, r - 1) + combination(n - 1, r);
}

bool ok(int ai, int aj, int bi, int bj) {
  double ta = V[ai] > 0 ? (double)L / V[ai] + T[ai] * aj : INF;
  double tb = V[bi] > 0 ? (double)L / V[bi] + T[bi] * bj : INF;
  return ta < tb;
}

int main(void) {
  cin >> N >> M >> L;
  REP(i, 0, N) cin >> P[i] >> T[i] >> V[i];

  REP(i, 0, N) REP(j, 0, M + 1) {
    p[i][j] =
        combination(M, j) * pow(P[i] / 100.0, j) * pow(1 - P[i] / 100.0, M - j);
  }

  REP(i, 0, N) {
    double ans = 0;
    double pi = 0;
    REP(j, 0, M + 1) {
      pi = p[i][j];
      double pij = pi;
      REP(k, 0, N) if (i != k) {
        double pk = 0;
        REP(l, 0, M + 1) if (ok(i, j, k, l)) pk += p[k][l];
        pij *= pk;
      }
      ans += pij;
    }
    printf("%.8lf\\n", ans);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
using namespace std;
typedef long long ll;

int N, M, L, P[100], T[100], V[100];
double p[100][51];

ll combination(ll n, ll r) {
  static ll comb[51][51];
  ll &ret = comb[n][r];
  if (ret != 0)
    return ret;
  if (n == 0 || r == 0)
    return ret = 1;
  if (n == r)
    return ret = 1;
  if (r == 1)
    return ret = n;
  return ret = combination(n - 1, r - 1) + combination(n - 1, r);
}

bool ok(int ai, int aj, int bi, int bj) {
  double ta = L / V[ai] + T[ai] * aj;
  double tb = L / V[bi] + T[bi] * bj;
  return ta < tb;
}

int main(void) {
  cin >> N >> M >> L;
  REP(i, 0, N) cin >> P[i] >> T[i] >> V[i];

  REP(i, 0, N) REP(j, 0, M + 1) {
    p[i][j] =
        combination(M, j) * pow(P[i] / 100.0, j) * pow(1 - P[i] / 100.0, M - j);
  }

  REP(i, 0, N) {
    double ans = 0;
    double pi = 0;
    REP(j, 0, M + 1) {
      pi = p[i][j];
      double pij = pi;
      REP(k, 0, N) if (i != k) {
        double pk = 0;
        REP(l, 0, M + 1) if (ok(i, j, k, l)) pk += p[k][l];
        pij *= pk;
      }
      ans += pij;
    }
    printf("%.8lf\\n", ans);
  }

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

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

#define DO(n) for (int ____n = n; ____n-- > 0;)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DWN(i, b, a) for (int i = b - 1; i >= a; --i)
#define REP_1(i, n) for (int i = 1; i <= n; ++i)
#define FOR_1(i, a, b) for (int i = a; i <= b; ++i)
#define DWN_1(i, b, a) for (int i = b; i >= a; --i)
#define RST(A) memset(A, 0, sizeof(A))
#define FLC(A, x) memset(A, x, sizeof(A))

typedef double DB;

const int N = int(1e2) + 9, M = int(5e1) + 9;
DB p[N][M], sp[N][M], t[N], t0[N];
int n, m, l;

DB f(int i, DB ti) {
  DB z = 1;
  REP(j, n) if (i != j) {
    if (t0[j] + m * t[j] <= ti)
      return 0;
    REP(k, m + 1) if (t0[j] + k * t[j] > ti) {
      z *= (1 - sp[j][k]);
      break;
    }
  }
  return z;
}

int main() {

  while (~scanf("%d%d%d", &n, &m, &l)) {

    RST(p);
    REP(i, n) {
      int _p, v;
      scanf("%d%lf%d", &_p, &t[i], &v);
      t0[i] = (DB)l / v;
      DB pp = (DB)_p / 100;
      // cout <<" " << pp << endl;
      p[i][0] = 1;
      DO(m) {
        DWN_1(j, m, 1) p[i][j] = p[i][j - 1] * pp + p[i][j] * (1 - pp);
        p[i][0] = p[i][0] * (1 - pp);
      }

      REP_1(j, m) sp[i][j] = sp[i][j - 1] + p[i][j - 1];
    }

    REP(i, n) {
      DB z = 0;
      REP(j, m + 1) z += p[i][j] * f(i, t0[i] + t[i] * j);
      printf("%.9f\\n", z);
    }
  }
}

Error: TLE

Fixed submission:

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

#define DO(n) for (int ____n = n; ____n-- > 0;)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define DWN(i, b, a) for (int i = b - 1; i >= a; --i)
#define REP_1(i, n) for (int i = 1; i <= n; ++i)
#define FOR_1(i, a, b) for (int i = a; i <= b; ++i)
#define DWN_1(i, b, a) for (int i = b; i >= a; --i)
#define RST(A) memset(A, 0, sizeof(A))
#define FLC(A, x) memset(A, x, sizeof(A))

typedef double DB;

const int N = int(1e2) + 9, M = int(5e1) + 9;
DB p[N][M], sp[N][M], t[N], t0[N];
int n, m, l;

DB f(int i, DB ti) {
  DB z = 1;
  REP(j, n) if (i != j) {
    if (t0[j] + m * t[j] <= ti)
      return 0;
    REP(k, m + 1) if (t0[j] + k * t[j] > ti) {
      z *= (1 - sp[j][k]);
      break;
    }
  }
  return z;
}

int main() {

#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

  while (~scanf("%d%d%d", &n, &m, &l)) {

    RST(p);
    REP(i, n) {
      int _p, v;
      scanf("%d%lf%d", &_p, &t[i], &v);
      t0[i] = (DB)l / v;
      DB pp = (DB)_p / 100;
      // cout <<" " << pp << endl;
      p[i][0] = 1;
      DO(m) {
        DWN_1(j, m, 1) p[i][j] = p[i][j - 1] * pp + p[i][j] * (1 - pp);
        p[i][0] = p[i][0] * (1 - pp);
      }

      REP(j, m + 1) cout << t0[i] << " ";
      cout << endl;

      REP_1(j, m) sp[i][j] = sp[i][j - 1] + p[i][j - 1];
    }

    REP(i, n) {
      DB z = 0;
      REP(j, m + 1) z += p[i][j] * f(i, t0[i] + t[i] * j);
      printf("%.9f\\n", z);
    }
  }
}