SRM 739, D1, 250-Pointer (ForumPostEasy)

James S. Plank

Tue Sep 18 17:11:37 EDT 2018

In Case Topcoder's Servers are Down

Here's a summary of the problem:

Examples


Testing yourself

Compile to a.out, and the output of tests.sh should match answers.txt In your a.out, if you give it a dash for a command line, then it will read all of the exact times on the first line, and all of the relative times on the second line. The relative times should have dashes instead of spaces, and it will convert them to spaces after reading them in:
UNIX> ./a.out -
12:12:12
few-seconds-ago
12:12:12
UNIX> 

Hints

When approaching Topcoder problems, my thought process usually goes, "Enumeration, Dynamic Programming, Something Else." If you use this approach, you'll come upon the solution pretty quickly -- instead of trying to calculate the time, simply enumerate all times. There are only 3600*24 = 86,400 of them. Enumerate them from smallest to largest. For each time t, run through all of the posts, and see if they are all legal at time t. If they are, then return t.

With 50 posts, doing O(1) work for each post, the running time is roughly calc 86400x50 = 4,320,000. That's easily within Topcoder's limits.

You'll benefit from some pre-processing. I created three arrays of integers:

To illustrate, here are the arrays for example 3: These arrays make it pretty easy for you to calculate the actual difference from time t, and then whether the "shown" difference is in the right interval. For example, when t is 43,163 (corresponding to 11:59:23), then you have: So, that time is ok, and you return it.

When you enumerate the values of t, simply enumerate the numbers from 0 to 86,399. When you get a legal one, you can create the return string and exit.