eolymp
bolt
Try our new interface for solving problems
Məsələlər

Stopped Watches

Stopped Watches

In the middle of Tyrrhenian Sea, there is a small volcanic island called Chronus. The island is now uninhabited but it used to be a civilized island. Some historical records imply that the island was annihilated by an eruption of a volcano about 800 years ago and that most of the people in the island were killed by pyroclastic flows caused by the volcanic activity. In \textbf{2003}, a European team of archaeologists launched an excavation project in Chronus Island. Since then, the project has provided many significant historic insights. In particular the discovery made in the summer of \textbf{2008} astonished the world: the project team excavated several mechanical watches worn by the victims of the disaster. This indicates that people in Chronus Island had such a highly advanced manufacturing technology. Shortly after the excavation of the watches, archaeologists in the team tried to identify what time of the day the disaster happened, but it was not successful due to several difficulties. First, the extraordinary heat of pyroclastic flows severely damaged the watches and took away the letters and numbers printed on them. Second, every watch has a perfect round form and one cannot tell where the top of the watch is. Lastly, though every watch has three hands, they have a completely identical look and therefore one cannot tell which is the hour, the minute, or the second (It is a mystery how the people in Chronus Island were distinguishing the three hands. Some archaeologists guess that the hands might be painted with different colors, but this is only a hypothesis, as the paint was lost by the heat.). This means that we cannot decide the time indicated by a watch uniquely; there can be a number of candidates. We have to consider different rotations of the watch. Furthermore, since there are several possible interpretations of hands, we have also to consider all the permutations of hands. You are an information archaeologist invited to the project team and are asked to induce the most plausible time interval within which the disaster happened, from the set of excavated watches. In what follows, we express a time modulo \textbf{12} hours. We write a time by the notation \textbf{hh:mm:ss}, where \textbf{hh}, \textbf{mm}, and \textbf{ss} stand for the hour (\textbf{hh = 00, 01, 02, ..., 11}), the minute (\textbf{mm = 00, 01, 02, ..., 59}), and the second (\textbf{ss = 00, 01, 02, ..., 59}), respectively. The time starts from \textbf{00:00:00} and counts up every second \textbf{00:00:00}, \textbf{00:00:01}, \textbf{00:00:02}, ..., but it reverts to \textbf{00:00:00} every \textbf{12} hours. The watches in Chronus Island obey the following conventions of modern analog watches. \begin{itemize} \item A watch has three hands, i.e. the hour hand, the minute hand, and the second hand, though they look identical as mentioned above. \item Every hand ticks \textbf{6} degrees clockwise in a discrete manner. That is, no hand stays between ticks, and each hand returns to the same position every \textbf{60} ticks. \item The second hand ticks every second. \item The minute hand ticks every \textbf{60} seconds. \item The hour hand ticks every \textbf{12} minutes. \end{itemize} At the time \textbf{00:00:00}, all the three hands are located at the same position. Because people in Chronus Island were reasonably keen to keep their watches correct and pyroclastic flows spread over the island quite rapidly, it can be assumed that all the watches were stopped in a short interval of time. Therefore it is highly expected that the time the disaster happened is in the shortest time interval within which all the excavated watches have at least one candidate time. You must calculate the shortest time interval and report it to the project team. \InputFile The input consists of multiple datasets, each of which is formatted as follows. \textbf{n} \textbf{s_1 t_1 u_1} \textbf{s_2 t_2 u_2} \textbf{...} \textbf{s_n t_n u_n} The first line contains a single integer \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{10}), representing the number of the watches. The three numbers \textbf{s_i}, \textbf{t_i}, \textbf{u_i} in each line are integers such that \textbf{0} ≤ \textbf{s_i}, \textbf{t_i}, \textbf{u_i} ≤ \textbf{59} and they specify the positions of the three hands by the number of ticks relative to an arbitrarily chosen position. Note that the positions of the hands of a watch can be expressed in many different ways. For example, if a watch was stopped at the time \textbf{11:55:03}, the positions of hands can be expressed differently by rotating the watch arbitrarily (e.g. \textbf{59 55 3}, \textbf{0 56 4}, \textbf{1 57 5}, etc.) and as well by permuting the hour, minute, and second hands arbitrarily (e.g. \textbf{55 59 3}, \textbf{55 3 59}, \textbf{3 55 59}, etc.). The end of the input is indicated by a line containing a single zero. \OutputFile For each dataset, output the shortest time interval within which all the watches given in the dataset have at least one candidate time. The output must be written in a single line in the following format for each dataset. \textbf{hh:mm:ss h′h′:m′m′:s′s′} Each line contains a pair of times \textbf{hh:mm:ss} and \textbf{h′h′:m′m′:s′s′}, indicating that the shortest interval begins at \textbf{hh:mm:ss} and ends at \textbf{h′h′:m′m′:s′s′} inclusive. The beginning time and the ending time are separated by a single space and each of them should consist of hour, minute, and second in two digits separated by colons. No extra characters should appear in the output. In calculating the shortest interval, you can exploit the facts that every watch has at least one candidate time and that the shortest time interval contains \textbf{00:00:00} only if the interval starts from \textbf{00:00:00} (i.e. the shortest interval terminates before the time reverts to \textbf{00:00:00}). If there is more than one time interval that gives the shortest, output the one that first comes after \textbf{00:00:00 }inclusive.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
3 
8 8 18 
32 32 32 
57 2 57 
5 
49 3 49 
7 30 44 
27 21 21 
33 56 56 
21 46 4 
3 
45 52 28 
36 26 36 
20 55 50 
10 
33 8 39 
50 57 43 
35 21 12 
21 17 11 
16 21 58 
45 40 53 
45 30 53 
39 1 8 
55 48 30 
7 48 15 
0
Çıxış verilənləri #1
00:00:00 00:00:10 
06:14:56 06:32:09 
07:27:37 07:32:02 
05:17:40 05:21:03
Mənbə Asia Regional Contest, Japan, AIZU, October 25-27, 2008