DMOPC '14 Contest 1 P4 - Perfect Timing

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

Being the friendly student you are, you decide to wait for Mr. Sidhu, your math teacher, in front of the Main Office as he delivers his attendance sheets. Since he is anxious to leave for home, he takes the shortest path possible, and walks at a speed of one metre per second.

The first line of input will consist of the coordinate for Mr. Sidhu's starting point while the following line will represent the coordinate of the Main Office. The coordinates satisfy (0 \le \text{coordinate} \le 10\,000). A colleague texts you exactly when Mr. Sidhu leaves the math science office and so you wish to calculate exactly how much time it will take him to arrive as to make the encounter seem like a "sheer coincidence".

Note that Mr. Sidhu can only walk horizontally and vertically — not diagonally.

Unfortunately, simply showing the number of seconds remaining just isn't that user-friendly, and so you decide to display Mr. Sidhu's Estimated Time of Arrival.

The format used will be as follows: YYYY:MM:DD:HH:MM:SS (years, months, days, hours – use 24 hour time, minutes, seconds). Make sure to match the format exactly (with leading zeroes, if necessary). Take into account any leap years that may occur.

Also, for your program to accommodate for the multiverse theory, the years of both the starting time and of the arrival time will be between 1970 and 5000.

Sample Input

0 0
2 2

Sample Output


Explanation for Sample Output

(0, 0) (0, 1) (0, 2)
(1, 0) (1, 1) (1, 2)
(2, 0) (2, 1) (2, 2)

Mr. Sidhu starts at (0, 0) and makes his way to (2, 2). Since he can walk only horizontally and vertically, he walks a total of 4 metres. At his speed of 1 m/s, it will take him 4 seconds.


  • 0
    omaewamoushindeiru  commented on Dec. 3, 2014, 6:31 p.m.

    I'm getting a "Number format exception" when I submit java. Am I not allowed to use this statement in the println?

    (s > 9 ? s : "0" + s)

    • 0
      FatalEagle  commented on Dec. 3, 2014, 6:42 p.m.

      There are multiple numbers on the same line of input.

  • 0
    quantum  commented on Nov. 6, 2014, 11:53 p.m.

    All test cases now have sane dates. No way you have to work with times so far back that you don't even know if it's Julian or Gregorian.

    • 2
      Kirito  commented on Feb. 27, 2016, 5:31 p.m.

      But my yogurt!