Final Standings
Time limit2sMemory limit512 MB
Given each team's strength, each problem's difficulty, and a frozen scoreboard, compute the probability that team t ends up in first place, assuming ties always go to team t.
- Level
Medium7 of 10
- Topics
- Probability, Dynamic programming, Math
- Solved
- No attempts yet
Problem
The GCPC 2019 is finally over. You have worked for five hours and have solved as many problems as possible. However, you still do not know which place you have got, since the scoreboard is still frozen. Of course you think that you and your team have won GCPC 2019.
As there is always a lengthy pause between the end of the contest and unfreezing the scoreboards (someone has to print the certificates and someone has to re-compile the solution slides), you want to use your time to determine how probable it is that your team has won GCPC 2019.
You know the final scoreboard, that is, for all teams which problems they have solved prior to the freeze and which problems they have attempted during the freeze. Also you know from last year how good each team is and you trust your own estimates of each problem's difficulty. To be precise, if a team with strength has attempted to solve a problem with difficulty , you assume that the probability of solving the problem is .
As your team was very quick in solving the simple problems this year, you assume that a team can only have a higher place than you if they have solved more problems (you assume that you will always win the tie-break).
Input
- The first line of input contains two integers and (), the number of teams and the number of problems in the contest. The teams are numbered to and the problems are numbered to . Your team is team .
- The second line contains real numbers ( for each ), where is the strength of team .
- The third line contains real numbers ( for each ), where is the difficulty of problem .
- Then follow lines describing the state of the problems for the other teams. Every such line contains characters , where in the th line describes the state of problem for team and is X if the team has solved the problem before the freeze, ? if the team submitted a program for this problem after the freeze, and - otherwise.
- The last line of input describes the problems your team solved with characters, each being either X or -.
All real numbers in the input have at most six decimals.
Output
Output a single real number, the probability that your team won GCPC 2019. Your answer should have an absolute or relative error of at most .