alarm | 프로그래밍의 벗 PivotOJ
PivotOJ

alarm

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2006 Regional Competition - JuniorsBOJ 3154
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

When we set the alarm on our mobile phone, we use the keyboard to enter four digits – the hours and the minutes. For example, if the desired time is 12:30, we press the digits 1, 2, 3 and 0. One-digit numbers are entered with the leading zero (for example, the number 9 is entered by punching in 09). 

Some time ago, our friend Mirko entered the wrong time and noticed that the hours displayed on the screen are actually the remainder of the hours entered divided by 24. Similarly, minutes displayed on the screen are the remainder of the minutes entered divided by 60. For example, if he punches in 66:79, the displayed time will be 18:19. 

Mirko is very lazy so he wants to use as little effort as possible to obtain the required time. Write a program that finds what time should be entered so that the correct time is displayed, and the minimum possible total effort is used. 

[이미지 1]

The effort needed for the finger to move from the key a to the key b is: 

effort(a,b) = |xa-xb|+|ya-yb|

where (xa, ya) and (xb, yb) are the row-column coordinates of the keys a and b in the keyboard layout given in the above figure. The total effort is defined as the sum of three values: effort to move from the first to the second digit, effort to move from the second digit to the third digit, and effort to move from the third digit to the forth digit. 

For example, total effort for to enter 22:45 is effort(2,2)+effort(2,4)+effort(4,5)=0+2+1=3. 

Note: If there are multiple solutions, output the earliest time. 

입력

The first and only line of input contains the desired time in the format HH:MM. One-digit numbers will be written with the leading zero. 

The desired time is valid and between 00:00 and 23:59, inclusive. 

출력

The first and only line of output should contain the correct solution in the format HH:MM. One-digit numbers should be written with the leading zero.

예제

예제 1

입력
14:19
출력
14:79

예제 2

입력
00:11
출력
24:11

예제 3

입력
12:34
출력
12:34
코드를 제출하려면 로그인하세요.