DMOPC '13 Contest 3 P2 - Phone Microwave

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 0.6s
Memory limit: 64M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Recently, you have lost all sense of time, constantly forgetting what year it is. You assume this is due to that fact that you are in possession of the infamous Phone Microwave, which sends text messages to the past — for every second the microwave is set to, the message will go an hour back in time. In a desperate attempt to fix your internal temporal clock (which was ruined by confusing your past self with messages about the future), you decide to send one last message telling you not to acquire the suspicious-looking microwave in the first place. To do so, you need to write a program telling you what time your past self will receive the message, based on the current time and the microwave's settings.

Given the date and setting on the microwave, figure out when your past self will receive the text. The microwave has a maximum time setting of 2 hours and you may assume that you always start between the years 2010 and 2011. The input will be given by the seconds and the time.

Input Specification

The first line of input contains an integer S, the Phone Microwave's time setting, in seconds. This value will not exceed 7\,200 (2 hours).

The second line of input contains the current date, given in this format:

YYYY/MM/DD HH:MM:SS

The year will be one of the years 2010 or 2011, the month will be a valid month from 01 to 12, and the day will be a valid day for that month. Here is a mnemonic to help you remember:

30 days hath September,
April, June and November,
All the rest have 31,
Excepting February alone
(And that has 28 days clear,
With 29 in each leap year).

The hour will be a valid hour from 00 to 23, and the minutes and seconds will each be a valid value ranging from 00 to 59.

Output Specification

You are to output the date when your past self receives the text, in the same format as the input as described in the previous section.

Constraints

Test Case BatchMarksConstraints
1 [3 cases]200 \le S \le 10
Additionally, your past self will receive the text on the same day.
2 [3 cases]300 \le S \le 48
Additionally, your past self will receive the text on the same month.
3 [3 cases]300 \le S \le 7\,200
Additionally, your past self will receive the text on the same year.
4 [3 cases]200 \le S \le 7\,200
No extra constraints.

Sample Input 1

120
2010/07/28 13:00:00

Sample Output 1

2010/07/23 13:00:00

Explanation for Sample Input 1

The Phone Microwave is set to 120 seconds, which takes you back exactly 5 days.

Sample Input 2

2
2011/01/01 01:23:45

Sample Output 2

2010/12/31 23:23:45

Explanation for Sample Input 2

The Phone Microwave takes you back 2 hours, which passes into the previous year.


Comments


  • 4
    BMP  commented on April 24, 2015, 3:40 p.m.

    I submitted the exact same code in both Java 8 and Java 7. However, Java 7 did not pass Batch #4 Case #2, where-as Java8 went all AC. Is it a compiler issue?


    • 1
      quantum  commented on April 26, 2015, 10:49 a.m.

      I am led to believe that it's timezone issues on the servers. Java 8 is only supported by one judge.


      • 1
        Xyene  commented on April 26, 2015, 11:12 a.m.

        A quick test reveals this to be the case: Java 7 submissions graded on Herculaneum get AC while those graded on the Sword judges get WA.


        • 1
          quantum  commented on April 26, 2015, 11:26 a.m.

          It would seem that the Sword judges are on either America/Toronto or America/New_York while Herculaneum is on Etc/UTC timezone. The test case in question crosses an odd number of DST boundaries, causing one hour difference.


          • 1
            BMP  commented on April 26, 2015, 1:37 p.m.

            I see, thanks guys!