This page is still under construction.

Parts of this page are still being built. What you see may change.

Clock Captcha

Time limit1sMemory limit128 MB

Summary
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 in HH:MM format, 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 ambiguous instead.

After the results of all displays, print a final line containing the single word end.

Examples5

  1. Example 1

    Input
    ....+  +---+     +---+  +---+
     ...|  |          .....     |
     ...|  |      .      ..   ...
    ....+  +-...     +--....    +
    ......     |  o  |   .....  |
    . . .     ...   ....        |
    ....+  +---+     +---+      +
    
    
    ....+  +---+     +---+  +---+
     ...|      |      .....     |
     ...|      |  .      ..   ...
    ....+  +-...     +--....    +
    ......     |  o  |   .....  |
    . . .     ...   ....        |
    ....+  +---+     +---+      +
    
    
    end
    
    Expected output
    15:27
    ambiguous
    end
    
  2. Example 2

    Input
    +---+  +---+     +---+  +---+
    |   |  |   |     |   |  |   |
    |   |  |   |  o  |   |  |   |
    +   +  +   +     +   +  +   +
    |   |  |   |  o  |   |  |   |
    |   |  |   |     |   |  |   |
    +---+  +---+     +---+  +---+
    end
    
    Expected output
    00:00
    end
    
  3. Example 3

    Input
    +---+  +---+     +---+  +---+
        |      |     |      |   |
        |      |  o  |      |   |
    +---+  +---+     +---+  +---+
    |          |  o      |      |
    |          |         |      |
    +---+  +---+     +---+  +---+
    end
    
    Expected output
    23:59
    end
    
  4. Example 4

    Input
    +---+  +---+     +   +  +---+
    |   |  |   |     |   |  |
    |   |  |   |  o  |   |  |
    +   +  +---+     +---+  +---+
    |   |      |  o      |      |
    |   |      |         |      |
    +---+  +---+         +  +---+
    end
    
    Expected output
    09:45
    end
    
  5. Example 5

    Input
        +  +---+     +---+  +---+
        |      |         |  |   |
        |      |  o      |  |   |
        +  +---+     +---+  +   +
        |  |      o      |  |   |
        |  |             |  |   |
        +  +---+     +---+  +---+
    end
    
    Expected output
    12:30
    end