Substring Removal Game

Source: Codeforces 1398B

  1. Read the problem and summarise the task.

You get points for deleting 1s, so it seems natural to take as many 1s as you can on each move. Before we start coding, we should convince ourselves that this strategy is actually optimal, and make plans to calculate the outcome systematically.

  1. If we take from a block of k consecutive 1s, should we always take all of them?

Now we have established that each move consists of taking either 0s or a whole block of 1s.

  1. Should we always take 1s instead of 0s (if both are present)?

There’s one last piece of the strategy to prove.

  1. Should we always take the largest block of 1s?

Now that we have an ideal strategy, let’s plan how to calculate the resulting scores.

  1. How would you identify the scoring moves that will be played?
  2. Implement this idea in code.
  3. How would you calculate the players’ scores?
  4. Implement this idea in code.
  5. The original problem has several test cases per file.
  6. Implement this idea in code.
  7. Submit your program for judging! - Debug as required.