Problem p01420 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PB push_back

typedef vector<double> vd;

const ll M = 1000000000;

class Runner {
public:
  vd goal_times;
  vd probabilities;

  Runner() {
    goal_times = vd();
    probabilities = vd();
  }

  void inspect() {
    cerr << "goal_times" << endl;
    REP(i, goal_times.size()) { cerr << " " << goal_times[i]; }
    cerr << endl;
    cerr << "probabilities" << endl;
    REP(i, probabilities.size()) { cerr << " " << probabilities[i]; }
    cerr << endl;
  }
};

ll combination(int n, int k) {
  ll ans = 1;
  FOR(i, 1, k + 1) {
    ans *= n - i + 1;
    ans /= i;
  }
  return ans;
}

const double EPS = 1e-9;
int main() {
  cout.precision(16);
  int N, M, L;
  cin >> N >> M >> L;
  vector<Runner> runners;
  REP(i, N) {
    Runner runner;
    double P;
    int T, V;
    cin >> P >> T >> V;
    P /= 100.0;
    double base_time = V > 0 ? (double)L / V : 1e20;
    REP(t_break, M + 1) {
      runner.goal_times.PB(base_time + T * t_break);
      runner.probabilities.PB(pow(P, t_break) * pow(1 - P, M - t_break) *
                              combination(M, t_break));
    }
    runners.PB(runner);
    // runner.inspect();
  }

  REP(i, runners.size()) {
    Runner &r = runners[i];
    double ans = 0;
    REP(t, M + 1) {
      double prize_prob = r.probabilities[t];
      REP(j, runners.size()) {
        if (i == j)
          continue;
        Runner &comp = runners[j];
        double win_prob = 0;
        REP(k, M + 1) {
          if (comp.goal_times[k] > r.goal_times[t] + EPS) {
            win_prob += comp.probabilities[k];
          }
        }
        prize_prob *= win_prob;
      }
      ans += prize_prob;
    }
    printf("%.8f\\n", ans);
    // cout << ans << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PB push_back

typedef vector<double> vd;

const ll M = 1000000000;

class Runner {
public:
  vd goal_times;
  vd probabilities;

  Runner() {
    goal_times = vd();
    probabilities = vd();
  }

  void inspect() {
    cerr << "goal_times" << endl;
    REP(i, goal_times.size()) { cerr << " " << goal_times[i]; }
    cerr << endl;
    cerr << "probabilities" << endl;
    REP(i, probabilities.size()) { cerr << " " << probabilities[i]; }
    cerr << endl;
  }
};

ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a;
  x = 1;
  y = 0;
  if (b != 0)
    g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

int mod_inverse(int a, int m) {
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}

// int fact[INT_MAX];
// int mod_fact(int n, int p, int &e)
//{
//	e = 0;
//	if (n == 0) return 1;
//	int res = mod_fact(n / p, p, e);
//	e += n / p;
//	if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
//	return res * fact[n % p] % p;
// }

// ll combination(int n, int k)
//{
//	if (n < 0 || k < 0 || n < k) return 0;
//	int e1, e2, e3;
//	int a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n -
//k, p, e3); 	if (e1 > e2 + e3) return 0; 	return a1 * mod_inverse(a2 * a3 % p, p)
//% p;
// }

// ll combination(int n, int k)
//{
//	if (k < 1) return 1;
//	ll bunshi = 1, bunbo = 1;
//	ll ans=1;
//	REP(i,n){
//		bunshi*=n-i;
//		bunshi%=M;
//	}
//	REP(i,k){
//		bunbo*=k-i;
//		bunbo%=M;
//	}
//	REP(i,n-k){
//		bunbo*=n-k-i;
//		bunbo%=M;
//	}
//	ans=bunshi;
//	ans*=mod_inverse
//	return mod_inverse(bunshi,
//
//	REP(i,n-k){
//		ans*=bunshi;
//		ans/=bunbo;
//		bunshi--;
//		bunbo--;
//	}
//	cerr << n << ", " << k << " => " << ans << endl;
//	return ans;
// }

ll combination(int n, int k) {
  if (k < 1)
    return 1;
  ll ans = 1;
  FOR(i, 1, n - k + 1) {
    ans *= n - i + 1;
    ans /= i;
  }
  return ans;
}

int main() {
  cout.precision(16);
  int N, M, L;
  cin >> N >> M >> L;
  vector<Runner> runners;
  REP(i, N) {
    Runner runner;
    double P;
    int T, V;
    cin >> P >> T >> V;
    P /= 100.0;
    double base_time = V > 0 ? (double)L / V : INT_MAX;
    REP(t_break, M + 1) {
      runner.goal_times.PB(base_time + T * t_break);
      runner.probabilities.PB(pow(P, t_break) * pow(1 - P, M - t_break) *
                              combination(M, t_break));
    }
    runners.PB(runner);
    runner.inspect();
  }

  REP(i, runners.size()) {
    Runner &r = runners[i];
    double ans = 0;
    REP(t, M + 1) {
      double prize_prob = r.probabilities[t];
      REP(j, runners.size()) {
        if (i == j)
          continue;
        Runner &comp = runners[j];
        double win_prob = 0;
        REP(k, M + 1) {
          if (comp.goal_times[k] > r.goal_times[t]) {
            win_prob += comp.probabilities[k];
          }
        }
        prize_prob *= win_prob;
      }
      ans += prize_prob;
    }
    cout << ans << endl;
  }
}