TCO 13: Marathon Finals, part 2

Part 1 Part 2 Part 3 Part 4

Multibase Solution

It’s 11:30, we’re 2,5h into the competition and I’m now absolutely forced to do the multibase strategy. No more running away. And I still have absolutely no clue how to do it. If something looks way too complex, it’s a good idea to try and split it into smaller parts. In this exact situation, I came up with the following subproblems:

  1. Which worker should build the base
  2. Where it should be placed
  3. When it should be placed
  4. When I have more than 1 base, how should I manage the workers
  5. How many bases I should build

Now I’m looking for the simplest way to accomplish each of those subproblems. First of all, let’s assume I’m trying to build at most 1 base at a time. (1) is pretty trivial. Let’s build it with any worker that can do it. Since there’s a constraint that only worker that doesn’t carry any resources can build the bases, let’s use only those. And if all of them are busy with carrying resources, just wait for one of them to be free. (2) is the scary part, so I just imagine that it isn’t here and I’m moving on with my list. The simplest solution to (3) is to build it as soon as we can (we have resources) and build the bases only after I have build all of my workers. Remember that in each simulation I know how many workers I’m going to get. For (4) I can just move each of my workers to the closest base. My intuition is that the workers will “manage themselves” after some time. It’s definitely far from perfect, but on the up side, I already have that implemented, so this is an ideal solution. (5) is even more trivial, because I use the number of bases as an input to my simulate() function and I’m assuming that I’ll just iterate over all possible combinations of workers and bases.

Continue reading

TCO 13: Marathon Finals, part 1

Part 1 Part 2 Part 3 Part 4

Disclaimer

Small warning first. This turned out to be a very long post. Mostly because, I tried to put here all of the important information, so that you can have a full picture of how does it feel to compete at the finals and at the same time have a peek at my thought process during those very long twelve hours. And for people who had never heard of TopCoder’s Marathons before – this is an algorithmic contest where your task is to solve one very hard problem for which there’s no polynomial-time optimal solution. We don’t have to use any APIs, we’re only submitting the code that is remotely executed. And the data (tests) that are used to test our solutions are almost always artificially generated and we’re provided with the generator itself – we just don’t know exact tests that are going to be used. And that is all you really need to know.

The origins for this post are pretty simple. I always thought that those regular “Post your approach” threads were telling only half of the story. The other half is obviously how people are coming up with those mentioned approaches. And since for me, the road itself is far more important than the goal, I wanted to shed some light on that process. My goal here is provide you with a very comprehensive portrayal of what’s going through my mind during the competition. And finally, going with the problem from the finals has many advantages – the contest duration is much shorter, so I can provide more details and the time management is significantly simplified since there are no real-life distractions.

Continue reading