Tactics
Time limit2sMemory limit1024 MB
Find the probability and average of X squared when the final score X of N random tactics is positive, and the same when it is negative, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Brute force, Sorting, Two pointers, Probability
- Solved
- No attempts yet
Problem
Ray is a player of the character collection game 'Blue Storage'. Today Ray is again practicing boss time attacks to get a high ranking. To defeat a boss faster than other players, one has to pull many strong characters, but Ray is a broke college student and could not pull many. Instead, Ray tries to set a good record by combining tactics, various strategies that can attack a boss efficiently.
Ray searched the game community overnight and found tactics in total. The -th tactic succeeds with probability and fails with probability . Tactics are executed in order. Ray's boss time attack score increases by if the -th tactic succeeds and decreases by if it fails.
Let be Ray's score after all tactics are executed. If is positive, Ray gains units of inner peace and plays the game harder. If is negative, Ray takes units of stress and becomes more likely to quit the game. Compute the inner peace and stress information Ray gets.
Input
The first line contains the number of tactics . ()
From the second line onward, the next lines each contain four integers , , , and , separated by spaces. and give the success probability of the -th tactic, is the points gained on success, and is the points lost on failure. (, )
All given numbers are integers. The tactics are given in the order in which they are executed.
Output
On the first line, print the probability that Ray gets inner peace after all tactics are executed, followed by the average of the inner peace value when Ray gets it.
On the second line, print the probability that Ray gets stress after all tactics are executed, followed by the average of the stress value when Ray gets it.
Only inputs where and are not are given.
For a fraction , is the integer with that satisfies . The integer is guaranteed to exist and be unique for every value to print.