Digital Clock
Time limit2sMemory limit128 MB
Given a broken 5x3 segment display for four digits where lit cells are always correct but some are missing, find the earliest valid hh:mm time consistent with the pattern.
- Level
Medium4 of 10
- Topics
- Brute force, Implementation, String
- Solved
- No attempts yet
Problem
Each room in a condo has a digital clock. The clock displays four digits in the form hh:mm: the first two digits are the hour, and the last two digits are the minute. Time is shown in the 24-hour system from 00:00 through 23:59.
Each digit is drawn with 15 light-emitting cells arranged in a 5 by 3 grid. Some cells are on to form a digit. In the diagram below, # means the cell is on and . means the cell is off.
### ..# ### ### #.# ### ### ### ### ###
#.# ..# ..# ..# #.# #.. #.. ..# #.# #.#
#.# ..# ### ### ### ### ### ..# ### ###
#.# ..# #.. ..# ..# ..# #.# ..# #.# ..#
### ..# ### ### ..# ### ### ..# ### ###
One morning, a guest notices that some cells of the clock are broken and therefore do not turn on. A cell that should be off is never incorrectly turned on. The guest wants to interpret the current time as early as possible; among valid times, 00:00 is considered earlier than every other time.
Given the four observed digits of the broken digital clock, find the earliest time that could have produced this display.
Input
Five lines are given. Each line has 15 characters: four digit blocks are written from left to right, each block has width 3, and adjacent blocks are separated by one space. Every non-space character is either # or ..
Output
Print the earliest possible time in the form hh:mm.