Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 3,198 Bytes
07f695f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<p>
You live on a circular road, <strong>L</strong> metres in length. Any point on the road can be referred to by a real number <strong>x</strong> 
(0 &le; <strong>x</strong> &lt; <strong>L</strong>), 
the distance along the road clockwise from its Northmost point to that point (in metres).
</p>

<p>
Fortunately for you, this road is served by public transportation! There are <strong>N</strong> bus stops at distinct, integral points along the road.
</p>

<p>
Unfortunately for you, due to budget cuts exactly <strong>K</strong> of these <strong>N</strong> stops will soon be removed. 
The group of <strong>K</strong> removed stops will be chosen uniformly at random from the set of all possible groups of <strong>K</strong> stops.
</p>

<p>
You'd like to calculate the expected distance you'll have to walk from a random point along the road, chosen uniformly at random from the interval [0, <strong>L</strong>), 
to the nearest of the remaining <strong>N</strong> - <strong>K</strong> bus stops, in metres.
</p>


<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of roads.
For each road, there is first a line containing the space-separated integers <strong>N</strong>, <strong>K</strong>, and <strong>L</strong>. 
Then follows a line containing a string of length <strong>L</strong>. This string consists of only the characters '0' and '1'.
There is a bus stop at position <strong>x</strong> if and only if the (<strong>x</strong> + 1)th character of the string is '1'.
Exactly <strong>N</strong> of the characters will be '1'.
</p>


<h3>Output</h3>
<p>
For the <strong>i</strong>th road, print a line containing "Case #<strong>i</strong>: " followed by
the expected distance you'll have to walk from a random point to the nearest bus stop, in metres. You should output the exact answer modulo (10<sup>9</sup> + 7).
That is, if the exact answer is <strong>a</strong> / <strong>b</strong>
 (where <strong>a</strong> and <strong>b</strong> are integers), you should output <strong>a</strong> * <strong>b</strong><sup>-1</sup> mod (10<sup>9</sup> + 7)
(where <strong>b</strong><sup>-1</sup> is the modular inverse of <strong>b</strong> mod (10<sup>9</sup> + 7)).
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 20 <br />
1 &le; <strong>N</strong> &le; 500,000 <br />
0 &le; <strong>K</strong> &lt; <strong>N</strong><br />
1 &le; <strong>L</strong> &le; 1,000,000 <br />
</p>


<h3>Explanation of Sample</h3>
<p>
In the first case, the single existing stop will remain untouched. If your starting position is smaller than 1 or greater than 5, you'll walk clockwise to it, for a distance of between 0m and 4m. Otherwise, you'll walk counterclockwise to it, also for a distance of between 0m and 4m. As such, your expected distance to walk will be 2m.
</p>
<p>
In the third case, one of the stops will be removed at random. Whichever one is removed, your situation will be similar to that of the first case - the distance you'll have to walk will be uniformly distributed between 0m and 4m, for an expected distance of 2m.
</p>
<p>
In the fourth case, the exact answer is 3.15 or 63/20, which is 550000007 when taken modulo (10<sup>9</sup> + 7).
</p>