Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi/főiskolai kategória, 2012. november 25.

November 25, 2012 11:30 AM – November 25, 2012 4:30 PM

Turn the Lights Off

Since we all rely on mother earth, it's our duty to save her. Therefore, you're now asked to save energy by switching lights off.

A friend of yours has the following problem in his job. There's a grid of size 10×10, where each square has a light bulb and a light switch attached to it. Unfortunately, these lights don't work as they are supposed to. Whenever a switch is pressed, not only its own bulb is switched, but also the ones left, right, above, and under it. Of course, if a bulb is on the edge of the grid, there are fewer bulbs switched.

When a light switches, it means it's now on if it was off before, and it's now off if it was on before. Look at the following examples, which show only a small part of the whole grid. They show what happens if the middle switch is pressed. “O” stands for a light that's on, “#” stands for a light that's off.

###      #O#
###  ->  OOO
###      #O#

###      #O#
OOO  ->  ###
###      #O#
    

Your friend loves to save energy and asks you to write a program that finds out if it is possible to turn all the lights off, and if possible then how many times he has to press switches in order to turn all the lights off.

Input Specification

There are several test cases in the input. Each test case is preceded by a single word that gives a name for the test case. The length of the name is between 1 and 100 characters. After that name there follow 10 lines, each of which contains a 10-character string consisting of “#” and “O”. The end of the input is reached when the name string is “end”.

Output Specification

For every test case, print one line that consists of the test case name, a single space character, and the minimum number of times your friend has to press a switch. If it is not possible to switch off all the lights, or it requires more than 100 presses, then the case name should be followed by a space and the number –1.

Sample Input

  1. all_off
  2. ##########
  3. ##########
  4. ##########
  5. ##########
  6. ##########
  7. ##########
  8. ##########
  9. ##########
  10. ##########
  11. ##########
  12. all_on
  13. OOOOOOOOOO
  14. OOOOOOOOOO
  15. OOOOOOOOOO
  16. OOOOOOOOOO
  17. OOOOOOOOOO
  18. OOOOOOOOOO
  19. OOOOOOOOOO
  20. OOOOOOOOOO
  21. OOOOOOOOOO
  22. OOOOOOOOOO
  23. simple
  24. #O########
  25. OOO#######
  26. #O########
  27. ####OO####
  28. ###O##O###
  29. ####OO####
  30. ##########
  31. ########O#
  32. #######OOO
  33. ########O#
  34. end
download as text file

Output for Sample Input

  1. all_off 0
  2. all_on 44
  3. simple 4
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019