F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Date

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 328    Accepted Submission(s): 71


Problem Description
Is it just another problem about year, month and day? No, today we have a more romantic meaning ¨C dating with a girl.
iSea now has a date to be anxious to rush, unfortunately, the city's way is always so complicated, so time goes unconsciously and fast. In order to more quickly rushed to rendezvous, iSea has already drawn a topographic map of this city, he find that the city is composed of a number of equal squares, between the squares, there are some traffic lights controlling the traffic, a basic map example:
Each time, iSea must proceed from the starting point of the upper left corner to reach the lower right corner. The squares¡¯ size is fixed, with a length of two meters and a width of one meter. iSea usually only go across the intersection under the green light, the time he costs is one minute, for safety's sake, in the whole one minute the green light should be lighten, we also know, iSea¡¯s speed along the grid is a constant, one meter per minute.
iSea¡¯s map gives some more specific information about the city, the number of vertical grid N, the number of horizontal grid M, and the time the traffic lights change alternating. In order to simplify the problem, we assume that one day start at 0 hour, traffic lights first allow passengers traverse the intersection from left and right, but block up and down in the intersection, after a time Ti, the traffic lights block left and right to allow access up and down, the time is also the Ti, so the cycle goes.
After simple calculation, iSea finds he may be late for this date, in order to reach the destination in time, he decides to make one exception, in an emergency he would pass through a intersection even if a red light was lighten, but not to loss of too many RP, he asks himself go across the red light at most once, then, can you help him, calculate when he could arrive in rendezvous at the earliest?
 

Input
There are several test cases in the input.

Each test case begin with two integers N, M (1 < N, M ¡Ü 30), indicating the number of the vertical grid and the horizontal grid.
Then N-1 lines follow, each line contains M-1 numbers Ti (0 < Ti ¡Ü 10), their meaning is in the description.
The last line is the start time of iSea, in the form of HH:MM.

The input terminates by end of file marker.
 

Output
For each test case, output the earliest time iSea can arrive, in the form of HH:MM, you may assume that all the things happen within the same day
 

Sample Input
2 2 3 12:03 2 3 2 2 12:00
 

Sample Output
12:05 12:05
 

Author
iSea @ WHU
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 17:28:34, Gzip enabled