What u could have done is simply check every substring of 3 if every such string contains 2 vowels it would be of alice else bob
Use log for calculations
Lets say alice prepared 100 dishes and all dishes are ‘aa’; Hence the denominator is pow(200, 100) (since 200 a’s and 100 dishes) which leads to overflow.
That’s why you should calculate it using logarithm.
There are three different parts because of which this problem can give you unsuccessful submission for your solutions.
Finding strings wrongly - Though this is easiest part to handle, but identifying strings correctly belonging to Alice and Bob can be tricky. For example for recipes like aaabbaaa (Bob), baabab (Bob),
abaabaabaa (Alice) etc.
Handling 10^5 test caes with 10 recipes of max length |S| <= 10 each. This can give you TLE for slow computtation when handling with the rest of the test cases. Notice that this particular case doesn’t exceed the double value type’s range, so you can simply handle the Sa and Sb in simple vars to improve the time complexity. Also, note that iterating through all 26 alphabets (even when absent in the inputs) here can also contribute to additional latency.
This is the second subtask of the problem. Handling cases where |S| <= 100000 and 10< L<= 100000. Here computing (fXa)^N and (fXb)^M can exceed the double value’s range. Here idea is that since you have to print only with accuracy of 10^-6, keep all Xa, Xb, fXa, fXb values in form of x.xxxxx,
like 1.35523535 and keep powers separately. like powerXa, powerXb, powerFxa, powerFxb.
compute result = (xA * fXb) / (xB * fXa) and power = powerXa + powerFxb - powerXb - powerFxa
if power >= 7, then print Infinity else print the actual result by adding back the resultant power to the result.
Compute all high powers in O(logN) and O(logM) time to avoid TLE.
The thing is pow(sa,a) can be extremely huge, like EXTREMELY HUGE because a can in the worst case be 10^5. so if we try to store pow(sa,a) and pow(sb,b) even in double, it is stored as inf.
So without using log theres the no way to solve this.
Thanks bro… I tried many different logic but could get only 25 marks …but after reading ur post my solution got accepted with 100 marks .
Thankyou very much.