luogu#P4978. 赌神:决斗
赌神:决斗
Background
God of Gambling is back!
Problem Description
decides to duel with !
It is known that has playing cards, and each card has an value . has playing cards, and each card has an value .
and will each choose an arbitrary contiguous interval of cards from their own decks to duel. Whoever has the larger sum of values within their chosen interval wins. Please help compute the probability that wins.
Input Format
- The first line contains two positive integers .
- The second line contains positive integers .
- The third line contains positive integers .
Output Format
Output one number representing the probability that wins. If the answer can be written in the form , then output (if you do not understand, see P3811).
5 5
1 2 3 4 5
1 3 5 7 9
754229067
10 15
7 8 5 1 2 3 6 5 4 1
52 10 5 6 3 2 1 4 5 8 7 4 5 6 3
181952721
1 1
5
5
0
5 5
1254125 36521421 25362142 12514221 25362142
857412252 36322411 2236232 1254112 36224125
261761853
2 2
2 4
2 5
332748118
Hint
Sample Explanation
- Sample : No matter how you choose, the result is always a tie on average, so the win rate is .
- Sample : There are possible ways in total, and tomoo wins times, so the win rate is .
Constraints
- For of the testdata, .
- For another of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5