Hints for SRM 615, D1, 250-pointer (AmebaDiv1)

James S. Plank

Tue Apr 8 18:16:17 EDT 2014
Problem Statement.
As far as D1-250's go, this was a pretty simple one. The only starting values for the amoeba are the values in X. However, you want to strip duplicates -- so create a set initial, with all of the unique values in X. That way, you have no duplicates.

Now, create another set, final, with potential final values. For each initial value in initial, simulate the the amoeba with that value. Calculate the ending value of the amoeba, and put it into final. At the end, you can run through initial again, and count the number of elements that are not also in final. That's the answer.

Let's look at examples:

Example X initial final Answer
0 {3, 2, 1} {1, 2, 3} {2, 4, 6} 2
1 {2, 2, 2, 2, 2, 2, 4, 2, 2, 2} {2, 4} {8} 2
2 {1, 2, 4, 8, 16, 32, 64, 128, 256, 1024, 2048} {1, 2, 4, 8, 16, 32, 64, 128, 256, 1024, 2048} {512, 4096} 11
3 {854, 250, 934, 1000, 281, 250, 281, 467, 854, 562, 934, 1000, 854, 500, 562} {250, 281, 467, 500, 562, 854, 934, 1000} {1000, 1124, 1708, 1868, 2000} 7

The running time complexity of this is O(n2), where n is the number of elements in X. Why is there no log term in that? Lets break it down:

Fortunately, the maximum value of n is 200, so O(n2) is fast enough to complete within Topcoder's limits.