Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 2,106 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
62
63
<p>
A top-secret algorithmic research facility has decided to up its security by hiring guards to keep watch over the premises. 
After all, they don't want anyone sneaking in and learning the answers to questions such as "does P = NP?" and 
"what are the solutions to the 2016 Facebook Hacker Cup problems?".
</p>

<p>
When viewed from above, the facility can be modeled as a grid <strong>G</strong> with 2 rows and <strong>N</strong> columns. 
The <strong>j</strong>th cell in the <strong>i</strong>th row is either empty (represented by <strong>G<sub>i,j</sub></strong> = ".") 
or occupied by a building (<strong>G<sub>i,j</sub></strong> = "X"), and the grid includes at least one empty cell.
</p>

<p>
Guards may be potentially stationed in any of the empty cells. A guard can see not only their own cell, but also all contiguous empty cells in each of the 4 compass directions 
(up, down, left, and right) until the edge of the grid or a building. For example, in the grid below, the guard ("G") can see every cell marked with an asterisk ("*"):
</p>

<pre>
.*.X.X..
*G*****X
</pre>

<p>
What is the minimum number of guards required such that every empty cell in the grid can be seen by at least one of them?
</p>


<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of facilities that need guarding.
For each facility, there is first a line containing the integer <strong>N</strong>. The next line contains the grid cells
<strong>G<sub>1,1</sub></strong> to <strong>G<sub>1,N</sub></strong> in order. The third line contains the grid cells
<strong>G<sub>2,1</sub></strong> to <strong>G<sub>2,N</sub></strong> in order.
</p>


<h3>Output</h3>
<p>
For the <strong>i</strong>th facility, print a line containing "Case #<strong>i</strong>: " followed by
the number of guards required to guard the facility.
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 200 <br />
1 &le; <strong>N</strong> &le; 1,000 <br />
</p>



<h3>Explanation of Sample</h3>
<p>
In the first case, one solution is to place three guards as follows:
</p>

<pre>
.G.X.XG.
....G..X
</pre>