SRM 719, D2, 250-Pointer (LongLiveZhangzj)

James S. Plank

Thu Sep 14 11:21:29 EDT 2017

In case Topcoder's servers are down

Here is a summary of the problem:

The examples


Testing yourself

Like the Cryptography Problem, I have a shell script tests.sh, that you can use to test your program. When you run tests.sh, your answer should be identical to answers.txt, and the running time should be well less than a second, total.

Hints

With the topcoder constraints being so low, a simply double-nested for loop will work. However, being the good computer scientist that you, dear reader, are, (and given the fact that my testing script increases those constraints), you will naturally take offense at writing an O(n2) solution to this problem.

Instead, insert the words in words into a set, and then for each word in speech(), try to find it in the set. Now your solution is O(n log n), and all is alsmost right with the universe.

Instead, substitute an unordered_set for the set, and your solution is O(n). Now all is indeed right with the universe.