Official Analysis (Python, Java)
Solution
We can subtract from because we will always get the sample test case and add it to our final answer.
Let be the expected value after at most submissions. We are trying to find . To get the expected value of the final submission, we can find the relation between and .
To do this we can find in terms of and which is the probability of getting exactly test cases.
After submissions, you expect to get test cases. There are three posibilites if you decide to resubmit.
Case 1: If you get less test cases than , you don't want to resubmit.
Case 2: If you get more test cases than , you do want to resubmit.
Case 3: If you get the same number of test cases as , it doesn't matter if you resubmit. In this case it wouldn't hurt to resubmit or stay the same so we can combine this with Case 1 (or Case 2).
The probability that you get less than or equal to test cases is . We can multiply this by the to get the expected value of if we stop before the th submission and we get
The probability that you get more than test cases is . The expected value of getting more than test cases is the sum of from to of the probability of getting test cases multiplied by or .
In addition, these formulas for both cases can help us mathematically prove that you can merge Case 3 with either Case 1 or 2. The only difference between both cases is whether the will belong to the first or second summation. If we merge it with Case 1, the term of the summation will become . If we merge it with Case 3, it would also become . This happens because is only satisfied when .
Adding the two parts gives our final expression for the expected value:
We can solve the problem by simulating each test case and recalculating the summations for each test case in . However, this can easily be sped up to by pre-calculating using Pascal's identity and by precalculating the prefix sums of both and so we can get the values of the summations in instead of . This gives us the first test cases but is not good enough.
In order to fully solve the question, we need to remove the factor. We can do this if we are able to process multiple values of in a single step.
Claim: We can process multiple queries if the values of and don't change between queries.
Proof: Let and . Then our formula becomes
Since and are constant, we can extend this formula and get
Simplifying gives us a geometric sequence.
We can rewrite the second through last term using the formula for a geometric series.
Here is more information about geometric series.
However, the values of and won't always remain the same. We can binary search on the max number of submissions Bessie can make before the values of and change. and will change when the value of changes. The conditions for binary search are fulfilled because is a non-decreasing function.
Since there are at most values of , and can change at most times so the resulting time complexity will be .
Implementation
Time Complexity:
C++
#include <bits/stdc++.h>using namespace std;using ll = long long;using db = double;const int MAXT = 1000;db prob[MAXT + 1][MAXT + 1];db pref_prob[MAXT + 1];
Python
import mathdef skip_submissions(a: float, b: float, e: float, x: float) -> float:"""Function that skips forward x submissionwith constants a and b and current expected value ebased on the geometric series formula"""return pow(a, x) * e + b * (pow(a, x) - 1) / (a - 1)
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!