Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2018 /round1 /evening.html
wjomlex's picture
2018 Problems
ab396f0 verified
<p>
A quiet evening has set over a residential area. As families sit down for supper in the safety of their homes, a calm atmosphere permeates the outside air.
The neighborhood feels truly at peace, separated from the frenzy of the rest of the world. Also, a bunch of zombies have just risen out of the ground and want to eat everybody.
</p>
<p>
The neighborhood has <strong>N</strong> yards in a row, numbered from 1 to <strong>N</strong>.
There are also <strong>N</strong>-1 fences, one between each pair of adjacent yards. The fence between yards <em>i</em> and <em>i</em>+1 has an unknown integral height
drawn uniformly at random from the inclusive interval [<strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong>].
In other words, the <em>i</em>th fence has <strong>B<sub>i</sub></strong> - <strong>A<sub>i</sub></strong> + 1 possible heights, each of which is equally likely.
</p>
<p>
<strong>M</strong> hungry zombies are also present, with the <em>i</em>th of them initially in yard <strong>Y<sub>i</sub></strong>.
Fortunately for the zombies, they might not be stopped by the surrounding fences so easily.
The <em>i</em>th zombie has the ability to climb over any fence with a height of at most <strong>H<sub>i</sub></strong>.
It may repeatedly move from its current yard to an adjacent one, as long as the fence between the yards is no taller than <strong>H<sub>i</sub></strong>.
Multiple zombies may start in the same yard, and multiple zombies may occupy the same yard at any point.
</p>
<p>
A yard is considered "safe" if it's impossible for any zombies to ever reach it. Determine the probability that at least one of the <strong>N</strong> yards is safe.
Let this probability be represented as a quotient of integers <em>p</em>/<em>q</em> in lowest terms.
Output the value of this quotient modulo 1,000,000,007 &mdash; in other words, output the unique integer <em>x</em> such that
0 &leq; <em>x</em> &lt; 1,000,000,007 and <em>p</em> = <em>x</em>*<em>q</em> (modulo 1,000,000,007).
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of neighborhoods.
For each neighborhood, there is first a line containing the space-separated integers <strong>N</strong> and <strong>M</strong>.
Then, <strong>N-1</strong> lines follow. The <em>i</em>th of these lines contains the space-separated integers
<strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong>.
Then, <strong>M</strong> lines follow. The <em>i</em>th of these lines contains the space-separated integers
<strong>Y<sub>i</sub></strong> and <strong>H<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <em>i</em>th neighborhood, print a line containing "Case #<em>i</em>: "
followed by 1 integer, the probability that at least one of the yards is safe, expressed as a quotient of integers modulo 1,000,000,007.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 75 <br />
1 &le; <strong>N</strong> &le; 3,000 <br />
1 &le; <strong>M</strong> &le; 3,000 <br />
1 &le; <strong>A<sub>i</sub></strong> &leq; <strong>B<sub>i</sub></strong> &le; 1,000,000 <br />
1 &le; <strong>Y<sub>i</sub></strong> &le; <strong>N</strong> <br />
1 &le; <strong>H<sub>i</sub></strong> &le; 1,000,000 <br />
</p>
<h3>Explanation of Sample</h3>
<p>
In the first case, if the height of the single fence is 100, then the zombie in yard 1 will be able to climb over it to reach yard 2, meaning that no yards will be safe. Otherwise, if the fence's height is 101, then yard 2 will be safe. Therefore, the probability that at least one of the yards is safe is 1/2 = 500000004 (modulo 1,000,000,007).
</p>
<p>
In the second case, in order for yard 2 to be safe from both surrounding zombies, the first fence's height must be either 3 or 4, and the second fence's height must be 4. The probability of this occurring is 2/4 * 1/4 = 1/8 = 125000001 (modulo 1,000,000,007).
</p>
<p>
In the third case, the probability of at least one yard being safe is 2/3 = 666666672 (modulo 1,000,000,007).
</p>