Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 1,343 Bytes
df6dd12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
A simple game consists of a grid of <b>R</b>x<b>C</b> buttons.  Each button
will be either lighted, or unlighted.  Whenever you push a button, the state
of that button, and its (up to) four neighbors will toggle -- lighted buttons
will become unlighted and unlighted buttons will become lighted.  Note that
the neighbors do not 'wrap' and thus a corner button has only two neighbors,
while an edge buttons has three.<br/><br/>
In this problem you will be given an initial configuration of the buttons.
Your task is to push the right buttons so that, when you are done, all of the
lights are turned on.  If there are multiple ways to do this, you should
determine the minimum number of buttons pushes that it can be done in.
<h3>Input</h3>
You will first read an integer <b>N</b> the number of test cases.  For each
test case, you will read two integers <b>R</b> and <b>C</b>.  This will
be followed by <b>R</b> whitespace-separated tokens, each containing <b>C</b> characters.  A 'X'
indicates a lighted button, while a '.' indicates an unlighted button.
<h3>Constraints</h3>
<ul>
<li><strong>N</strong> = 20</li>
<li>1 &le; <b>R</b>,<b>C</b> &le; 18</li>
</ul>
<h3>Output</h3>
For each test case you should output the minimum number of button presses
required to turn on all the lights.  If there is no way to do this, you should
output -1.