Clock Captcha
Time limit1sMemory limit128 MB
Decode a 7-line seven-segment clock image with dots as wildcards and print the unique valid time or ambiguous.
- Level
Medium5 of 10
- Topics
- Implementation, Simulation, Brute force
- Solved
- No attempts yet
Problem
An office uses a digital display clock together with a camera to keep documents from being backdated. The camera photographs the office at regular intervals and records the exact time at which each document was signed and stamped, so the pictures can later serve as evidence.
Your task is to scan one such picture, decode the digital clock shown in it, and report the time.
The clock shows a time in HH:MM (24-hour) format on a seven-segment display. Each of the four digits is drawn inside a cell that is 5 characters wide and 7 lines tall, using the characters +, -, |, and space. The ten digits look exactly like this:
0 1 2 3 4 5 6 7 8 9
+---+ + +---+ +---+ + + +---+ +---+ +---+ +---+ +---+
| | | | | | | | | | | | | |
| | | | | | | | | | | | | |
+ + + +---+ +---+ +---+ +---+ +---+ + +---+ +---+
| | | | | | | | | | | | |
| | | | | | | | | | | | |
+---+ + +---+ +---+ + +---+ +---+ + +---+ +---+
The whole display is exactly 7 lines tall and 29 columns wide. Reading left to right, the first digit occupies columns 1-5, then 2 blank columns, the second digit occupies columns 8-12, the colon separator occupies columns 13-17 (it is drawn with the letter o), the third digit occupies columns 18-22, then 2 blank columns, and the fourth digit occupies columns 25-29.
Input
The input contains one or more scanned displays, one after another. Consecutive displays are separated by one or more blank lines. After the last display, a line containing the single word end marks the end of the input.
Because scanning a picture is error-prone, some characters of a display may not have been recognized correctly. Every such character is replaced by a dot (.). Thanks to a reliable error-detecting mechanism it is always known which characters were unreadable, so a dot may stand for any character that could legitimately appear in that spot.
It is guaranteed that every display is consistent with at least one valid time (00:00 through 23:59).
Output
For each display, in the order given, print one line:
- If exactly one valid time (
00:00-23:59) is consistent with the picture, print that time inHH:MMformat, with leading zeros. - If two or more valid times are consistent with the picture, printing any single one would risk giving wrong information, so print the word
ambiguousinstead.
After the results of all displays, print a final line containing the single word end.