A model's Codeforces rating is estimated by repeatedly sampling a few of its candidate solutions per problem, scoring the contest, ranking it against humans and converting the rank into a rating. Implement four functions.
submission_score(outcomes, penalty_medians): outcomes are booleans in submission order. For the first solved submission with k earlier failures, return float(penalty_medians[min(k, len(penalty_medians) - 1)]); return 0.0 if nothing is solved.
contest_rank(score, human_scores): 1 + the number of human scores strictly greater than score.
performance_rating(rank, human_ratings, lo=0.0, hi=4000.0, iters=50): the whose expected seed over the human ratings equals rank. Do iters bisection steps on [lo, hi]: if the seed at the midpoint exceeds rank, set lo to the midpoint, otherwise set hi; return the final midpoint.
estimate_elo(results, penalty_medians, human_scores, human_ratings, n_samples=100, n_pick=10, seed=0): results[p] is the list of candidate outcomes for problem p and penalty_medians[p] its median table. Create rng = np.random.default_rng(seed) once. Repeat n_samples times: for each problem in order, take rng.permutation(len(results[p]))[:min(n_pick, len(results[p]))] as the submission order and score it; sum the scores into a contest score, convert it to a rank and then to a performance rating. Return {"expected_rating", "mean_score", "min_rating", "max_rating"} (mean rating, mean contest score, min and max rating), each rounded to 2 decimals.